我需要一个只能输出与某个国家/地区相关的地方的代码。换句话说,我需要找到半径/边界内的地点。对于Instance Sydney.自动完成代码只显示悉尼的地方
由于
答案 0 :(得分:0)
<input id="autocomplete" placeholder="Enter your address" type="text"></input>
function initAutocomplete() {
//5 mile bounds around orlando, fl
var streetLng = -81.43061;
var streetLat = 28.56683;
var center = new google.maps.LatLng(parseInt(streetLat), parseInt(streetLng));
var north = google.maps.geometry.spherical.computeOffset(center, 5, 0).lat();
var east = google.maps.geometry.spherical.computeOffset(center, 5, 90).lng();
var south = google.maps.geometry.spherical.computeOffset(center, 5, 180).lat();
var west = google.maps.geometry.spherical.computeOffset(center, 5, -90).lng();
var defaultBounds = new google.maps.LatLngBounds(new google.maps.LatLng(north, east), new google.maps.LatLng(south, west));
new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')), {
componentRestrictions: { country: "us" }, types: ['address'], bounds: defaultBounds
});
}
initAutocomplete();