function getLatLong(address){
var geo = new google.maps.Geocoder;
geo.geocode({'address':address},function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
return results[0].geometry.location;
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
这将返回一个对象,您可以使用.lat()和.lng()来获取纬度和经度 .
27
您可以使用 :
var address = "New Delhi";
$.ajax({
url: "http://maps.googleapis.com/maps/api/geocode/json?address="+address+"&sensor=false",
type: "POST",
success: function(res){
console.log(res.results[0].geometry.location.lat);
console.log(res.results[0].geometry.location.lng);
}
});
2 回答
当你说发送json时你不能确定你的意思,但是你可以用这个函数做到这一点:
这将返回一个对象,您可以使用.lat()和.lng()来获取纬度和经度 .
您可以使用 :
Sample Response:
Demo :http://jsbin.com/riyakobero/edit?html,js,console,output