如何将纬度和经度值转换为javascript中的地址?我试过地理定位,但它只显示了10个地址。它不会显示超过十个地址。我的代码:
if (result.Status.code == G_GEO_SUCCESS) {
for ( var i = 0; i < result.Placemark.length; i++) {
var addres = result.Placemark[i].address;
// var t1=setTimeout(function(){x.value="2 seconds"},2000);
if (addres == "") {
// alert('blank');
document.getElementById("msg" + noofid).innerHTML = "Unable to find location";
} else {
document.getElementById("msg" + noofid).innerHTML = result.Placemark[i].address;
}
//alert("address");
}
}
// ====== Decode the error status ======
else {
var reason = "Code " + result.Status.code;
if (reasons[result.Status.code]) {
reason = reasons[result.Status.code];
}
alert('Could not find "' + search + '" '
+ reason);
}
});
}发布于 2013-09-05 10:57:00
你好,因为您有一个关于这个api的特定问题,我遇到了您的问题,我将与您分享我的一个有类似需求的老项目的一些来源。
// get nearest coords based on given tracking
tb.prototype.getNearestStreetCoords = function(lat, lng, callback) {
var parentClass = this;
var nearestStreet = {
latitude: lat,
longitude: lng
};
if (parentClass.useNearest != true) callback(nearest);
var request = {
origin: new google.maps.LatLng(lat, lng),
destination: new google.maps.LatLng(lat, lng),
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
callback(response);
} else {
callback(false);
}
});
}
// get nearest address based on lat & lng
tb.prototype.getAddress = function(lat, lng, callback) {
geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': new google.maps.LatLng(lat, lng)}, function(results, status) {
var streetAddress = null;
if (status == google.maps.GeocoderStatus.OK) {
streetAddress = results[0].formatted_address;
}
callback(streetAddress);
});
}https://stackoverflow.com/questions/18634146
复制相似问题