perfacilis/geocoder
最新稳定版本:0.2.2
Composer 安装命令:
composer require perfacilis/geocoder
包简介
Simple Geocoder with Cache using Google Maps API
README 文档
README
Uses PSR SimpleCache interface to allow for query results to be stored.
This is a standalone library, no Laravel or other Frameworks, to keep it as simple and lightweight as possible, but rest assured, it'll work with Laravel just fine :)
Installation
composer require perfacilis/geocoder
Usage
Get a Google Maps API key
See: https://console.cloud.google.com/apis/credentials
Create a new API key, ensure to:
- restrict it to your IP(s) only;
- restrict it to use the Geocoding API only.
If you're using the Google Maps JS API you'll probably have to create a different key because that key should be restricted to HTTP referers (web sites).
Simple Example
$api_key = '123foo456bar'; $geocoder = new Perfacilis\Geocoder\Geocoder($api_key); $result = $geocoder->geocode('Street 12, 1234AB, Residence, Country'); $lat = $result->getLat(); $lng = $result->getLng();
Enabling Cache
Since Google's Geocoding API is on a Pay-Per-Use basis, it's recommended to implement your own Cacher using PSR's SimpleCache interface:
$api_key = '123foo456bar'; $cacher = new GeocoderCache(); $geocoder = new Perfacilis\Geocoder\Geocoder($api_key); $geocoder->setCacheInterface($cacher); $result = $geocoder->query(...);
You can manually create a cacher to store results in a simple database:
class GeocoderCache implements Psr\SimpleCache\CacheInterface { ... }
统计信息
- 总下载量: 361
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-15