shumex/geocode
Composer 安装命令:
composer require shumex/geocode
包简介
Google Geocode API for Laravel
README 文档
README
A simple Laravel service provider for Google Geocoding API.
Installation
This package can be installed via Composer.
Run composer require command.
composer require shumex/geocode
Laravel 5.5
Both the service provider and alias will be automatically installed by Laravel 5.5 package discovery.
Configuration
Add the following line to the .env file:
GEOCODE_GOOGLE_APIKEY=<your_google_api_key>
You can optionally set the response language.
GEOCODE_GOOGLE_LANGUAGE=en # pt-BR, es, de, it, fr, en-GB
Supported Languages for Google Maps Geocoding API.
Usage
You can find data from addresses:
try { $response = Geocode::make()->address('Saporischschja', 'de'); if ($response) { echo $response->latitude(); echo "<br>"; echo $response->longitude(); echo "<br>"; echo $response->formattedAddress(); echo "<br>"; } } catch (GeoException $exception) { echo $exception->getMessage(); } // Output // 35.139567 // 47.8388 // Saporischschja, Ukraine, 69061
Or from latitude/longitude:
try { $response = Geocode::make()->latLng(47.850437, 35.135653, 'en'); if ($response) { echo $response->latitude(); echo "<br>"; echo $response->longitude(); echo "<br>"; echo $response->formattedAddress(); echo "<br>"; } } catch (GeoException $exception) { echo $exception->getMessage(); } // Output // 47.850437 // 35.135653 // Volhohrads'ka St, 27, Zaporizhzhia, Zaporiz'ka oblast, Ukraine, 69000
If you need other data rather than formatted address, latitude, longitude, you can use the raw() method:
try { $response = Geocode::make()->latLng(40.7637931,-73.9722014); if ($response) { echo $response->raw()->address_components[8]['types'][0]; echo $response->raw()->address_components[8]['long_name']; } } catch (GeoException $exception) { echo $exception->getMessage(); } // Output // postal_code // 10153
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-22