jeroendesloovere/geolocation-bundle

该地理位置Symony2 Bundle使用了geolocation-php-api类,通过Google Maps API从地址查找纬度和经度,或反向查找。

1.0.0 2015-06-09 08:28 UTC

This package is auto-updated.

Last update: 2024-08-24 03:37:47 UTC


README

该地理位置Symony2 Bundle使用了Google Maps API的geolocation-php-api类,可以从地址查找纬度和经度,或反向查找。

使用方法

安装

{
    "require": {
        "jeroendesloovere/geolocation-bundle": "1.0.*"
    }
}

将以下代码添加到您的composer.json文件中,将通过Composer获取[jeroendesloovere/geolocation-bundle的最新版本包](https://packagist.org.cn/packages/jeroendesloovere/geolocation-bundle)。

并在app/AppKernel.php中

public function registerBundles()
{
    $bundles = array(
        // ...,
        new JeroenDesloovere\Bundle\GeolocationBundle\JeroenDesloovereGeolocationBundle()
    );
}

示例

$geolocation = $this->get('jeroendesloovere.geolocation');

// define result
$result = $geolocation::getCoordinates('Koningin Maria Hendrikaplein', '1', 'Gent', '9000', 'belgië');

// dump result
echo 'Coordinates = ' . $result['latitude'] . ', ' . $result['longitude'] . '<br/>';

// define result: @return array(label, street, streetNumber, city, cityLocal, zip, country, countryLabel)
$result = $geolocation::getAddress(51.0363935, 3.7121008);

// define result
echo 'Address = ' . $result['label'] . '<br/>';