如何限制Google Places autocomplete API 在一定的经纬度范围内按半径?
How to restrict Google Places autocomplete API by a radius within a certain longitude and latitude?
我正在使用文档中提到的这段代码
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
如何严格限制坐标一定半径的结果?
Google 的代码示例使用 setBounds()
:
将自动完成结果偏向用户的地理位置
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({center: geolocation, radius: position.coords.accuracy});
autocomplete.setBounds(circle.getBounds());
});
}
}
要真正限制 自动完成结果到给定范围,使用strictBounds
:
autocomplete.setOptions({strictBounds: true})
希望对您有所帮助。
我正在使用文档中提到的这段代码 https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
如何严格限制坐标一定半径的结果?
Google 的代码示例使用 setBounds()
:
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({center: geolocation, radius: position.coords.accuracy});
autocomplete.setBounds(circle.getBounds());
});
}
}
要真正限制 自动完成结果到给定范围,使用strictBounds
:
autocomplete.setOptions({strictBounds: true})
希望对您有所帮助。