0
votes

is there a way to show only cities in a google map api autocomplete field?

At the moment we are using Geocode but unfortunately we receive even countries and addresses.

We even tried the following code

var input = document.getElementById('txt_city_and');
var options = {
  types: ['(cities)']
};

autocomplete = new google.maps.places.Autocomplete(input, options);

and the error we receive is

Uncaught TypeError: Cannot read property 'Autocomplete' of undefined

-- Thank you

1
ok we have found the solution by using the following code var input = document.getElementById('txt_city_and'); var options = { types: ['(cities)'] }; and when we call the library we added the following code &libraries=places example: <script type="text/javascript" src="maps.google.com/maps/api/…> - user1908483
The autocomplete library is actually a separate library that must be explicitly loaded. maps.googleapis.com/maps/api/… - thomasbabuj
Thank you for your answer, how do we get postcodes or zip codes from this autocomplete? Many thanks - user1908483
stackoverflow.com/questions/12236857/… , check under the address_components. - thomasbabuj

1 Answers

0
votes

Please, ensure that <script type="text/javascript" src="maps.google.com/maps/api/... is placed before the script with the code that uses it