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文档。