2016-07-12 118 views
3

试图添加谷歌自动完成在Laravel。我的代码如下 -谷歌地图自动完成与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文件的输出类似但─

enter image description here

然而,当我想实现Laravel,它根本不工作。它显示以下错误。 enter image description here

你能帮我解决这个问题吗?

+0

你这包括谷歌API的脚本文件? –

+0

@DharaParmar,其更新... tisuchi

+0

你在哪里注入您的API密钥? –

回答

3

您需要在url中添加密钥,此错误的原因是您尚未配置Google Maps API密钥。

可参考见 - 如何创建键:http://docs.gravityview.co/article/306-signing-up-for-a-google-maps-api-key

添加关键网址:

<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> 
+0

我跟着你...但是,尚未修复...现在没有更多的错误,但没有输出tooo – tisuchi

+0

这里是输出http://我。 stack.imgur.com/x4kVj.png – tisuchi

+0

你能为我提供关键吗? –