assghard/php-geocoders
最新稳定版本:0.2.2
Composer 安装命令:
composer require assghard/php-geocoders
包简介
Geocoders library for PHP project
README 文档
README
Simple PHP library which provides geocoding and reverse geocoding features using different providers such as Nominatim (OpenStreetMap), Google, etc. Get address by coordinates and get coordinates by address
Requirements
- PHP >= 8.0
- PHP cURL
Installation
Install latest release (for PHP 8+):
composer require assghard/php-geocoders
For older versions of PHP
If you use PHP 7+: composer require assghard/php-geocoders:dev-php7
If you use PHP 5.6: composer require assghard/php-geocoders:dev-php56
Usage
Nominatim geocoder
Add GeocodingService and NominatimGeocoderProvider in uses section
use Assghard\PhpGeocoders\GeocodingService; use Assghard\PhpGeocoders\Providers\NominatimGeocoderProvider;
$geocoder = new NominatimGeocoderProvider(); $geocodingService = new GeocodingService($geocoder); // Get coordinates by address $geocodeData = $geocodingService->geocode($addressAsString); // Get address by coordinates $reverseData = $geocodingService->reverse($latitude, $longitude);
You can also provide country code/codes to Geocoder provider:
$geocoder = new NominatimGeocoderProvider('en');
Multiple country codes:
$geocoder = new NominatimGeocoderProvider(['en', 'pl']);
Google geocoder
use Assghard\PhpGeocoders\GeocodingService; use Assghard\PhpGeocoders\Providers\GoogleGeocoderProvider;
...
$geocoder = new GoogleGeocoderProvider('GOOGLE_MAPS_API_KEY', 'en'); /** * "en" - English language code. See Google documentation: https://developers.google.com/admin-sdk/directory/v1/languages * * Google Maps javascript API documentation: https://developers.google.com/maps/documentation/javascript/overview */ $geocodingService = new GeocodingService($geocoder); $geocodeData = $geocodingService->geocode($addressAsString); // Get coordinates by address $reverseData = $geocodingService->reverse($latitude, $longitude); // Get address by coordinates
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-08