salmanzafar / laravel-geocode
用于查找给定具体地址的经纬度的Laravel库
v1.0.5
2020-10-12 13:53 UTC
Requires
- php: ^7.0 || ^7.1 || ^7.2 || ^7.3 || ^7.4
- laravel/framework: ^5.5 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- ext-curl: *
README
从特定地址获取经纬度的Laravel包。
目录
安装
composer require salmanzafar/laravel-geocode
配置
发布配置文件
php artisan vendor:publish --provider="Salman\GeoCode\GeoCodeServiceProvider"
Config/geocode.php
'API_KEY' => env('GOOGLE_GEOCODE_API_KEY', ''),
启用包(可选)
此包实现了Laravel自动发现功能
使用
您需要Google地图地理编码 api密钥才能使用此功能
查找坐标
use Salman\GeoCode\Services\GeoCode; public function lookForPoints() { $address = "1600 Amphitheatre Parkway,Mountain View"; $getPoints = new GeoCode(); return $getPoints->getLatAndLong($address); }
使用门面查找坐标
use GeoCode; public function lookForPoints() { $address = "1600 Amphitheatre Parkway,Mountain View"; return GeoCode::getLatAndLong($address); }
使用辅助函数查找坐标
public function lookForPoints() { $address = "1600 Amphitheatre Parkway,Mountain View"; return findAddressCoordinates($address); }
响应
它将返回一个Laravel集合作为响应
{
"address_components": [
{
"long_name": "1600",
"short_name": "1600",
"types": [
"street_number"
]
},
{
"long_name": "Amphitheatre Parkway",
"short_name": "Amphitheatre Pkwy",
"types": [
"route"
]
},
{
"long_name": "Mountain View",
"short_name": "Mountain View",
"types": [
"locality",
"political"
]
},
{
"long_name": "Santa Clara County",
"short_name": "Santa Clara County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "California",
"short_name": "CA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "94043",
"short_name": "94043",
"types": [
"postal_code"
]
}
],
"formatted_address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"geometry": {
"location": {
"lat": 37.4220579,
"lng": -122.0840897
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 37.42340688029149,
"lng": -122.0827407197085
},
"southwest": {
"lat": 37.4207089197085,
"lng": -122.0854386802915
}
}
},
"place_id": "ChIJtYuu0V25j4ARwu5e4wwRYgE",
"plus_code": {
"compound_code": "CWC8+R9 Mountain View, CA, USA",
"global_code": "849VCWC8+R9"
},
"types": [
"street_address"
]
}