1001pharmacies / geolocation-bundle
提供地理编码服务的抽象层。
v1.1.1
2017-11-02 07:10 UTC
Requires
- php: >=5.5
- ext-curl: *
- guzzlehttp/guzzle: 6.*
Requires (Dev)
- phing/phing: ~2.9
- phpunit/phpunit: 4.*
- sami/sami: 2.0.*
- sebastian/phpcpd: 2.*
- squizlabs/php_codesniffer: 2.*
- symfony/symfony: 2.3.*
This package is not auto-updated.
Last update: 2024-09-20 20:41:41 UTC
README
提供地理编码服务的抽象层。此捆绑包还可以用于在多个外部地理编码服务之间分割地理编码的计算。
支持的提供商
以下服务包含在本捆绑包中
有关添加您自己的提供商的完整文档,请参阅此处。
示例
空间坐标和邮政地址对应关系
地址获取坐标
$address = $container ->get('meup_geo_location.address_factory') ->create() ->setFullAddress('360 rue du thor, 34000 Montpellier') ; $coordinates = $container ->get('meup_geo_location.locator') ->locate($address) ; printf( "%s,%s\n", $coordinates->getLatitude(), $coordinates->getLongitude() ); // output : 43.6190815,3.9162419
geolocation-bundle
仅提供库和服务。但您可以轻松地将它集成到您的应用程序中。
坐标获取地址
$coordinates = $container ->get('meup_geo_location.coordinates_factory') ->create() ->setLatitude(43.6190815) ->setLongitude(3.9162419) ; $address = $container ->get('meup_geo_location.locator') ->locate($coordinates) ; print $address->getFullAddress(); // output : 640 Rue du Mas de Verchant, 34000 Montpellier
距离计算
当您找到两个位置的坐标时,您还可以使用距离计算器计算它们的距离。
$factory = $container ->get('meup_geo_location.coordinates_factory') ; $paris = $factory ->create() ->setLatitude(48.856667) ->setLongitude(2.350987) ; $lyon = $factory ->create() ->setLatitude(45.767299) ->setLongitude(4.834329) ; $distance_paris_lyon = $container ->get('meup_geo_location.distance_calculator') ->getDistance($paris, $lyon) ; printf('%d km', $distance_paris_lyon); # 391.613 km
安装
使用Composer安装此包
composer require 1001pharmacies/geolocation-bundle
或更新composer.json
文件
"require": { "1001pharmacies/geolocation-bundle": "~1.0" }
更新app/AppKernel.php
$bundles = array( // ... new Meup\Bundle\GeoLocationBundle\MeupGeoLocationBundle(), );
使用您的API密钥设置app/config/parameters.yml
parameters: # ... geo_location_google_api_key: your_google_api_key geo_location_bing_api_key: your_bing_api_key geo_location_nominatim_api_key: null geo_location_mapquest_api_key: your_mapquest_api_key geo_location_yandex_api_key: null geo_location_heredotcom_api_key: your_heredotcom_api_key
有关获取API密钥的详细信息,请参阅Google和Bing的文档。