rapidwebltd/simple-google-maps-api
最新稳定版本:v2.0.2
Composer 安装命令:
composer require rapidwebltd/simple-google-maps-api
包简介
a simple api for the google maps services
README 文档
README
This library allows a user to easily communicate with the Google Maps API and retrieve a set of coordinates from an address.
Installation
To install, just run the following composer command.
composer require rapidwebltd/simple-google-maps-api
Remember to include the vendor/autoload.php file if your framework does not do this for you.
Usage
Creating the SimpleGoogleMaps Object can be done in one of two ways.
The first way is to pass through just the API key that you are provided upon registering for the Google Maps API.
use RapidWeb\SimpleGoogleMaps\Factories\SimpleGoogleMapsFactory; $simpleGoogleMaps = SimpleGoogleMapsFactory::getByKey("[APIKEY]");
The second way is to provide your client name and the crypt key that you are provided with upon creating a Google enterprise account.
use RapidWeb\SimpleGoogleMaps\Factories\SimpleGoogleMapsFactory; $simpleGoogleMaps = SimpleGoogleMapsFactory::getByClientNameAndCryptKey("[CLIENTNAME]","[CRYPTKEY]");
Once you have created the object you can then get the coordinates from an address via the getByAddress method.
$addressline = "10 Downing St, Westminster, London SW1A UK"; $homeCoords = $simpleGoogleMaps->getByAddress($addressline);
Optionally, you can allow partial matches to be returned if your input address is not highly accurate. You can do so with the allowPartialMatches method, as shown below.
$simpleGoogleMaps->allowPartialMatches(); $homeCoords = $simpleGoogleMaps->getByAddress('test address');
The above method will return a object of type LatLong, this allows you to access the coordinates like so.
$latitude = $homeCoords->lat; $longitude = $homeCoords->long;
You can also calculate the distance between two LatLong objects by using the distanceTo method on the LatLong Object.
$milesBetween = $homeCoords->distanceTo($toCoords);
By default this will return the answer in miles, you may also request the distance in kilometres by adding it to the method call.
$milesBetween = $homeCoords->distanceTo($toCoords,"kilometres");
统计信息
- 总下载量: 12.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-only
- 更新时间: 2017-03-29