I am trying to use the Google Elevation API with the getJSON function of JQuery.
I am using this code which is using JSONP :
jQuery.getJSON("http://maps.googleapis.com/maps/api/elevation/json?locations=23.444,45.4545&sensor=false&jsoncallback=?", function(json){
alert("a");
});
I can see in Firebug that the GET request is correctly send and I receive the correct response from Google :
{
"status": "OK",
"results": [ {
"location": {
"lat": 23.4440000,
"lng": 45.4545000
},
"elevation": 816.7996216
} ]
}
However I never the Alert and I get this error from Firebug :
invalid label
"status": "OK",\n
I am using the Google Maps API v2 so I connato use the build in method.
Is there any way to get the elevation with the Google Elevation API via an AJAX request and without creating a proxy?
Thanks for your help.
Benjamin
The Google elevation API don't support JSONP (Thanks to Nick Craver for the explanation) and I cannot use the ElevationService which is only available for the v3 Google Maps API.
So I decided to use an other webservice to get the elevation :
http://www.geonames.org/export/web-services.html#astergdem
example : http://ws.geonames.org/astergdemJSON?lat=X&lng=Y&callback=?
This webservice support JSONP, so it can be use easily with JQuery and the getJSON method.
Benjamin