Laravel 5.8: Google 地图 API 自动完成错误
Laravel 5.8: Google map API auto complete errors
我在我的 laravel 5.8 项目中使用地理定位。
我想在搜索框中使用 google 地图 API 自动完成功能。我创建了自己的 API 密钥,并粘贴了 link 但它不起作用。
我试了 3 links。第一个是:
<script src="https://maps.googleapis.com/maps/api/js?key=KEY&libraries=places&callback=initAutocomplete" async defer></script>
然后错误如下。
This API project is not authorized to use this API.
其次,我试过这段代码:
<script async defer src="https://maps.googleapis.com/maps/api/js?key=KEY&callback=initMap"
Uncaught (in promise). initMap is not a function
最后,我把这个:
<script src="https://maps.googleapis.com/maps/api/place/autocomplete/json?input=1600+Amphitheatre&key=KEY&sessiontoken=1234567890" async defer></script>
Uncaught ReferenceError: google is not defined
错误点在这里:footer.blade.php
您的项目似乎没有启用 Places API。按照 this link 中的步骤启用它。确保 JavaScript API 也已启用。
此外,您不能在 client-side JavaScript 中调用 Places API 网络服务。 Web 服务是 server-side。要了解 Places API (web service) and the Places library(JS API client-side 服务)之间的区别,请参阅 Google 的文档。
要实施自动完成,您可以使用 this example 作为指导。
希望对您有所帮助!
我在我的 laravel 5.8 项目中使用地理定位。
我想在搜索框中使用 google 地图 API 自动完成功能。我创建了自己的 API 密钥,并粘贴了 link 但它不起作用。
我试了 3 links。第一个是:
<script src="https://maps.googleapis.com/maps/api/js?key=KEY&libraries=places&callback=initAutocomplete" async defer></script>
然后错误如下。
This API project is not authorized to use this API.
其次,我试过这段代码:
<script async defer src="https://maps.googleapis.com/maps/api/js?key=KEY&callback=initMap"
Uncaught (in promise). initMap is not a function
最后,我把这个:
<script src="https://maps.googleapis.com/maps/api/place/autocomplete/json?input=1600+Amphitheatre&key=KEY&sessiontoken=1234567890" async defer></script>
Uncaught ReferenceError: google is not defined
错误点在这里:footer.blade.php
您的项目似乎没有启用 Places API。按照 this link 中的步骤启用它。确保 JavaScript API 也已启用。
此外,您不能在 client-side JavaScript 中调用 Places API 网络服务。 Web 服务是 server-side。要了解 Places API (web service) and the Places library(JS API client-side 服务)之间的区别,请参阅 Google 的文档。
要实施自动完成,您可以使用 this example 作为指导。
希望对您有所帮助!