juskiewicz/geolocation

支持Google Geocoding API的库

v1.1 2018-11-14 19:27 UTC

This package is auto-updated.

Last update: 2024-09-17 00:51:29 UTC


README

Latest Stable Version License

Geolocation类连接Google Maps API并搜索坐标或地址。

安装

Composer

使用Composer可以始终下载最新版本。

composer require juskiewicz/geolocation

请查看Packagist

使用示例

getCoordinatesByObject

通过Address对象获取Coordinates对象。

$streetName = 'Maltańska';
$streetNumber = '1',
$postalCode = '61-131',
$locality = 'Poznań',
$country = 'Polska',

$address = new Address(
    null,
    $streetName,
    $streetNumber,
    $postalCode,
    $locality,
    $country
);

$geolocation = new Geolocation('YOUR_GOOGLE_MAPS_API_KEY', 'pl', 'pl');
$coordinates = $coordinates = $geolocation->getCoordinatesByObject($address);

// Współrzędne
$latitude = $coordinates->getLatitude();
$longitude = $coordinates->getLongitude();
$tablica = $coordinates->toArray();

getCoordinatesByString

通过字符串获取Coordinates对象。

$address = "Maltańska 1, 61-131 Poznań, Polska";
$geolocation = new Geolocation('YOUR_GOOGLE_MAPS_API_KEY', 'pl', 'pl');
$coordinates = $geolocation->getCoordinatesByString($address);

getAddress

通过Coordinates对象获取Address对象。

$latitude = 51.8990865;
$longitude = 17.7863699;

$coordinates = new Coordinates($latitude, $longitude);

$geolocation = new Geolocation('YOUR_GOOGLE_MAPS_API_KEY','pl', 'pl');
$address = $geolocation->getAddress($coordinates);

查看Geolocation类的源代码。查看Address类的源代码。查看Coordinates类的源代码。