0
我想查找澳大利亞哪個城市的最近城市example在此查看示例。我嘗試過使用Google API,但沒有用。我該如何實現這一目標。你可以幫幫我嗎?如何在Google地圖API中找到距離最近的城市
代碼
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var request = {
location: fenway,
radius: 500,
types: ['store']
};
var service = new google.maps.places.PlacesService(map);
service.search(request, callback);
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var lat = results[i].geometry.location.lat();
var geocoder = new google.maps.Geocoder();
var lng = results[i].geometry.location.lng();
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({
'latLng': latlng
}, function (result, status1) {
if (status == google.maps.GeocoderStatus.OK) {
if (result[1]) {
console.log(result[1]);
}
} else {
alert("Geocoder failed due to: " + status1);
}
});
}
}
}
我想在城市附近不喜歡商店等。我必須找到在澳大利亞郊區有哪些近,而我給
我添加了我的代碼,我試過了。你有什麼建議嗎? – muthu 2012-07-25 12:27:10
以前也曾經有過相同的問題:http://stackoverflow.com/search?q=nearest+towns+cities&submit=search – Marcelo 2012-07-25 12:56:50