Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Places Autocomplete missing geometry

The Google Maps Places Autocomplete does not work as expected anymore.

https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

When inserting a search string in the map (for example "ZKM"), it will give some recommendations in the drop down list. In this case it will be "ZKM | Zentrum für Kunst und Medientechnologie Karlsruhe, Lorenzstraße, Karlsruhe, Deutschland". When clicking this item, no marker will be placed on the map!

But when searching for "Karlsruhe" and clicking the first search result "Karlsruhe, Deutschland" the marker is placed correctly.

In the code a function called getPlace() ist called.

var place = autocomplete.getPlace();

The place should contain an object "geometry", but it does not.

Is there any workaround for this problem?

like image 414
Michael Avatar asked Jan 26 '15 21:01

Michael


People also ask

How do I add autocomplete to a Google Maps page?

In order to use autocomplete, you must first load the Google Places library using the libraries parameter in the bootstrap URL for the Google Maps JavaScript API. The Places API offers two types of autocomplete widgets, which you can add via the Autocomplete and SearchBox classes respectively. Autocomplete adds a text input field on your web page.

How do I use autocomplete widgets in the Places API?

The Places API offers two types of autocomplete widgets, which you can add via the Autocomplete and SearchBox classes respectively. Autocomplete adds a text input field on your web page. As the user enters text, autocomplete returns place predictions in the form of a dropdown pick list.

How to disable strict bounds for Autocomplete in Google Maps?

// Autocomplete. // 1. Unbind from map // 2. Reset the bounds to whole world // 3. Uncheck the strict bounds checkbox UI (which also disables strict bounds) Note: Read the guide on using TypeScript and Google Maps. // This example requires the Places library. Include the libraries=places // parameter when you first load the API. For example:

How do I restrict the autocomplete search to a specific area?

The radio buttons allow you to filter the types of predictions that the autocomplete returns. The Strict Bounds option restricts the search to the area within the current viewport. If this option is not checked, then the API biases the search to the current viewport, but it does not restrict it.


Video Answer


1 Answers

Please be sure you set 'geometry' field in autocomplete like this:

autocomplete.setFields(['address_component', 'geometry']);

like image 186
Maxim Georgievskiy Avatar answered Sep 22 '22 05:09

Maxim Georgievskiy