M
M
Maxim2016-09-26 12:56:41
Google
Maxim, 2016-09-26 12:56:41

How to limit Google AutoComplete?

Is it possible in google autocomplete to limit the search so that it searches only for streets and only in a certain city?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
elfirin, 2019-03-26
@elfirin

I solved the problem by limiting the search radius. Here is the documentation for the getQueryPredictions Places API method, which mentions the request parameter, which passes the request object. This object can contain the location and radius parameters, with which we set the coordinates of the center of the circle and the radius of the circle inside which we will search. location - object of type LatLng, radius - numeric value in meters (maximum 50,000)
Below is my example, the center of Moscow is hardcoded. All similar search methods work similarly and accept these parameters.

service.getQueryPredictions({
    input: text,
    location: new google.maps.LatLng(55.751482, 37.619126),
    radius: 50000
}, displaySuggestions);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question