I'm loading the Google Maps API, jQuery and this Geocomplete plugin. Please note that I'm also specifying the libraries (libraries=places) and eventually my API key:
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<script src='http://maps.googleapis.com/maps/api/js?v=3&sensor=false&libraries=places&key=xxx'></script>
<script src='js/vendor/jquery.geocomplete.js'></script>
I'm triggering the Geocomplete plugin on the page load
$(window).load(function () {
$('#my-input').geocomplete();
});
but I always get an error:
Uncaught TypeError: Cannot read property 'Autocomplete' of undefined [jquery.geocomplete.js:153].
Inside the plugin...
this.autocomplete = new google.maps.places.Autocomplete(
this.input, options
);
I tried to google.maps and it returns a regular object, but places is undefined!
From the control panel, select the search engine you want to edit. Click Search features from the menu on the left and then click the Autocomplete tab. Click on the slider to set Enable autocomplete to On. It can take up to 2-4 days for autocompletions tailored to your search engine to start appearing.
Google Map with Autocomplete Search BoxCreate an input element ( searchInput ) where the autocomplete addresses search will be added. Create a DIV element ( map ) to display the Google Map. Specify the elements to display the geolocation data.
It is currently not possible to restrict results to a specific locality. You can use bounds as you have done so above to bias results towards, but not restricted to places contained within the specified bounds. If you believe restriction by locality would be a useful feature please file a Places API - Feature Request.
I tried to google.maps and it returns a regular object, but places is undefined!
That means the google.maps.places library is not loading (the line of code that you posted, shown below is either not correct or is not actually on your page):
<script src='http://maps.googleapis.com/maps/api/js?v=3&sensor=false&libraries=places&key=xxx'></script>
This is the example from the documentation:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
The only obvious difference is the &
in yours, that should work, but you should probably use it consistently.
TL;DR
Use &libraries
not &libraries
and it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With