Problem with connecting to google map url to fetch lattitude and longitude for particular location
I have the following code to fetch lattitude and longitude for given address but the permission to google url is denied .
function getlatlng(address, callback) { var addressval = address; var address; var url; var googleUrl = "http://maps.google.com/maps/api/geocode/json?"; var sensor = "&sensor=false";
if (addressval != null && addressval != "" && addressval.length != 0) {
address = "address=" + encodeURIComponent(addressval);
$.ajax({
url: googleUrl + address + sensor,
type: "POST",
async: false,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(longlatJson) {
var jsonObj = JSON.parse(JSON.stringify(longlatJson));
var lat = jsonObj.results[0].geometry.location.lat;
var lng = jsonObj.results[0].geometry.location.lng;
cb(lat, lng);
},
error: function() { alert("unable 开发者_开发知识库to conect to google server"); }
});
}
}
This will be my function call to getlatlng for the given address
getlatlng(address, function(lat, lng) { alert(lat); alert(lng); ............... ...............
});
You don't need a key for v3.
The problem is that the Google Maps JSON web service does not use jsonp so you can't use it how you are becuase you are hitting the cross domain policy of browsers.
You either need to have your server do that request (via wget or something) and then pass the results back to the browser or instead use the Google Maps API geocoder and that will handle it for you.
You can read more here http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding
I don't see any reference to an API key in your code; do you send it with your requests ?
精彩评论