最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Map Autocomplete with Laravel - Stack Overflow

programmeradmin6浏览0评论

Trying to add google autoplete in Laravel. My code is like follows-

<script type="text/javascript" src=";libraries=places"></script>
<script type="text/javascript">
    google.maps.event.addDomListener(window, 'load', function () {
        var places = new google.maps.places.Autoplete(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" />

Its absolutely works in HTML / PHP file. The output in html/php file is like that-

However, when I wanna implement in Laravel, its not working at all. It shows the following error.

Can you help me to fixed this one?

Trying to add google autoplete in Laravel. My code is like follows-

<script type="text/javascript" src="http://maps.googleapis./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.Autoplete(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" />

Its absolutely works in HTML / PHP file. The output in html/php file is like that-

However, when I wanna implement in Laravel, its not working at all. It shows the following error.

Can you help me to fixed this one?

Share Improve this question edited Jul 19, 2016 at 9:22 tisuchi asked Jul 12, 2016 at 6:45 tisuchitisuchi 9641 gold badge15 silver badges19 bronze badges 4
  • which google api script file you included? – Dhara Parmar Commented Jul 12, 2016 at 6:49
  • @DharaParmar, its update now... <script type="text/javascript" src="maps.googleapis./maps/api/…> – tisuchi Commented Jul 12, 2016 at 6:53
  • where you inject your API key? – Hamed Nemati Commented Jul 12, 2016 at 6:59
  • In raw html/php file, it works fine without API key.. – tisuchi Commented Jul 12, 2016 at 7:00
Add a ment  | 

1 Answer 1

Reset to default 5

You need to add key in url, the reason of this error is that you haven't configured your Google Maps API keys yet.

Refer to see - How to create key: http://docs.gravityview.co/article/306-signing-up-for-a-google-maps-api-key

Add key to url:

<script src="https://maps.googleapis./maps/api/js?key=YOUR API KEY&libraries=places"></script>

or use this url:

<script type="text/javascript" src="https://maps.googleapis./maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
发布评论

评论列表(0)

  1. 暂无评论