vdvcoder/geocode
最新稳定版本:1.0
Composer 安装命令:
composer require vdvcoder/geocode
包简介
Google Geocoding 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 vdvcoder/geocode
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:
$response = Geocode::make()->address('1 Infinite Loop'); if ($response) { echo $response->latitude(); echo $response->longitude(); echo $response->formattedAddress(); echo $response->locationType(); } // Output // 37.331741 // -122.0303329 // 1 Infinite Loop, Cupertino, CA 95014, USA // ROOFTOP
Or from latitude/longitude:
$response = Geocode::make()->latLng(40.7637931,-73.9722014); if ($response) { echo $response->latitude(); echo $response->longitude(); echo $response->formattedAddress(); echo $response->locationType(); } // Output // 40.7637931 // -73.9722014 // 767 5th Avenue, New York, NY 10153, USA // ROOFTOP
If you need other data rather than formatted address, latitude, longitude or location type, you can use the raw() method:
$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']; } // Output // postal_code // 10153
That's it. Pull requests are welcome.
统计信息
- 总下载量: 28
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-22