我使用getPlacePredictions来获取结果自动完成谷歌地图。 我在莫斯科使用中心地图。 我阅读了文档https://developers.google.com/maps/documentation/javascript/reference#AutocompletionRequest
我看到radius类型编号并以米为单位(50000)。 但是,我在距离650000上得到了结果。示例I键入“Sara”并获得结果“Saransk,Россия”。 我的位置 - 是莫斯科。 莫斯科和萨兰斯克距离650 000米。
示例我的代码: 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) });我怎么解决这个问题?
我尝试使用getQueryPredictions和getPredictions来代替getPlacePredictions但我得到了相同的结果。
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.
最满意答案
你可以使用strictBounds参数。 但AutocompleteService不支持。 更多信息。
在这里。
You will can strictBounds parametrs. But AutocompleteService is not support. More info.
And here.
为什么财产“半径”不工作getPlacePredictions谷歌地图(Why property “radius” don't work getPlacePredictions google maps)我使用getPlacePredictions来获取结果自动完成谷歌地图。 我在莫斯科使用中心地图。 我阅读了文档https://developers.google.com/maps/documentation/javascript/reference#AutocompletionRequest
我看到radius类型编号并以米为单位(50000)。 但是,我在距离650000上得到了结果。示例I键入“Sara”并获得结果“Saransk,Россия”。 我的位置 - 是莫斯科。 莫斯科和萨兰斯克距离650 000米。
示例我的代码: 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) });我怎么解决这个问题?
我尝试使用getQueryPredictions和getPredictions来代替getPlacePredictions但我得到了相同的结果。
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.
最满意答案
你可以使用strictBounds参数。 但AutocompleteService不支持。 更多信息。
在这里。
You will can strictBounds parametrs. But AutocompleteService is not support. More info.
And here.
发布评论