I use getPlacePredictions
for get result autocomplete google maps. I use center map in Moscow. And I read documentation https://developers.google.com/maps/documentation/javascript/reference#AutocompletionRequest
I see radius
type number and specified in meters (50000). But I get results on distance 650000. Example I keyup "Sara" and get result "Saransk, Россия". My location - is Moscow. The distance is 650 000 meters beetwen Moscow and Saransk.
Example my code: https://jsfiddle.net/bg479gna/33/
const autoComplete = new google.maps.places.AutocompleteService();
const input = document.querySelector('#search');
const result = document.querySelector('#result');
const getPlaceAutocomplete = (value) => {
autoComplete.getPlacePredictions({
input: value,
location: new google.maps.LatLng(55.755826, 37.617300), //Moscow
radius: 50000, //this value 50km. But i get cities on distance 650km. WHY?!?!
componentRestrictions: {
country: 'ru',
},
}, (data) => {
data.forEach((item) => {
result.innerHTML += `<li>${item.description}</li>`
});
});
};
input.addEventListener('keyup', () => {
const value = input.value;
getPlaceAutocomplete(value)
});
How can I solve this problem?
And I try to use getQueryPredictions
and getPredictions
instead getPlacePredictions
but I get the same results.