2016-07-15 113 views
-2

我需要一个只能输出与某个国家的特定城市相关的地方的代码。换句话说,我需要在半径/边界内找到地点。例如Sydney.the自动完成代码只显示悉尼的地方,没有别的。谷歌地图api自动完成特定城市的输出地点

感谢

+0

SO不是软件写作服务...你应该为[描述问题(http://meta.stackoverflow.com/questions/254393),并显示已做了什么到目前为止解决它 – Marusyk

+0

@MegaTron hi..here是代码... – Lucky

回答

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(); 
+0

请更改经纬度和朗悉尼 – Ray

+0

输出结果显示在澳大利亚的所有地方/城市..我已添加库“https:// “maps.googleapis.com/maps/api/js?sensor=false&libraries=places,geometry”但不起作用.... – Lucky

相关问题