尝试在 Laravel 中添加谷歌自动完成功能。我的代码如下-
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('txtPlaces'));
google.maps.event.addListener(places, 'place_changed', function () {
});
});
</script>
<span>Location:</span>
<input type="text" id="txtPlaces" style="width: 250px" placeholder="Enter a location" />
它绝对适用于 HTML/PHP 文件。 html/php 文件中的输出是这样的-
但是,当我想在 Laravel 中实现时,它根本不起作用。它显示以下错误。
你能帮我解决这个问题吗?
最佳答案
你需要在url中添加 key ,这个错误的原因是你还没有配置你的谷歌地图API key 。
请参阅 - 如何创建 key :http://docs.gravityview.co/article/306-signing-up-for-a-google-maps-api-key
将 key 添加到 url:
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR API KEY&libraries=places"></script>
或使用此网址:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
关于javascript - 使用 Laravel 自动完成谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38321753/