Search code examples
google-mapslaravel-5google-maps-api-3autocompletegeolocation

Laravel 5.8: Google map API auto complete errors


I am using geolocation in my laravel 5.8 project.

I want to use google map API auto complete in the search box. I created my own API key, and pasted link but it doesn't work.

I tried 3 links. First one is:

<script src="https://maps.googleapis.com/maps/api/js?key=KEY&libraries=places&callback=initAutocomplete" async defer></script>

And then the error is the below.

This API project is not authorized to use this API.

Secondly, I tried this code:

<script async defer src="https://maps.googleapis.com/maps/api/js?key=KEY&callback=initMap"

Uncaught (in promise). initMap is not a function

Lastly, I put this:

<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

and error point is here: footer.blade.php

error code


Solution

  • It looks like you have not enabled the Places API on your project. Follow the steps in this link to enable it. Make sure that the JavaScript API is also enabled.

    Also, you cannot call the Places API web service in client-side JavaScript. Web services are server-side. To understand the difference between Places API (web service) and the Places library (JS API client-side service) please refer to Google's documentation.

    To implement Autocomplete you can use this example for guidance.

    Hope this helps!