[英]Laravel 5.5 Geocoder
I wanted to use this package for geocoding in Laravel. 我想在Laravel中使用这个包进行地理编码。 I have added it to providers and published the config, but I am getting trouble setting it up to work.
我已将其添加到提供程序并发布配置,但我无法将其设置为工作。
try {
$location = Geocoder::geocode('68.145.37.34')->get();
return $location;
} catch (\Exception $e) {
return $e;
}
This returns empty object. 这将返回空对象。
I have left the config file as is. 我按原样离开了配置文件。
return [
'cache-duration' => 9999999,
'providers' => [
Chain::class => [
GoogleMaps::class => [
'en-US',
env('GOOGLE_MAPS_API_KEY'),
],
GeoPlugin::class => [],
],
],
'adapter' => Client::class,
];
And added valid API key to env
. 并为
env
添加了有效的API密钥。 Is there something I'm missing? 有什么我想念的吗?
Geocoder is imported as use Geocoder\\Laravel\\Facades\\Geocoder;
Geocoder导入
use Geocoder\\Laravel\\Facades\\Geocoder;
EDIT 编辑
In case someone gets to the same problem...this is how you'd get the country from it: 如果有人遇到同样的问题......这就是你从国家获得这个国家的方式:
app('geocoder')->geocode('5.43.168.58')->get()->first()->getCountry()->getName();
Really complicated unnecessarily in my opinion, I requested a documentation change on official repo. 在我看来,我不必要地复杂化,我要求在官方回购中更改文档。
did you try using dd() in tinker?? 你尝试在修补匠中使用dd()吗? I have been try it...and it work for me..
我一直在尝试......它对我有用..
try this : 试试这个 :
dd(app('geocoder')->geocode('68.145.37.34')->get());
response : 回应:
Illuminate\Support\Collection {#764
items: array:1 [
0 => Geocoder\Model\Address {#753
-coordinates: Geocoder\Model\Coordinates {#755
-latitude: 51.0823
-longitude: -113.9578
}
-bounds: null
-streetNumber: null
-streetName: null
-subLocality: null
-locality: "Calgary"
-postalCode: null
-adminLevels: Geocoder\Model\AdminLevelCollection {#767
-adminLevels: array:1 [
1 => Geocoder\Model\AdminLevel {#768
-level: 1
-name: "Alberta"
-code: "AB"
}
]
}
-country: Geocoder\Model\Country {#769
-name: "Canada"
-code: "CA"
}
-timezone: null
-providedBy: "geo_plugin"
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.