Get LatLon from Google with Mootools Request.JSONP -
i trying fetch latlon data request google. request.jsonp request works fine , returns data perfect, @ onsucces returns 'invalid label' error.
here script:
var g = {} var googleurl = 'http://maps.googleapis.com/maps/api/geocode/json?address='; g.google = function(id){ var address = '500-504 w 20th st, new york, ny 10011, usa'; var thisurl = googleurl + address + '&sensor=true'; new request.google(thisurl, { onsuccess: function(data) { console.log(data); } }).send(); } request.google = new class({ extends: request.jsonp, options: {}, initialize: function(thisurl, options) { this.parent(options); this.options.url = thisurl; }, success: function(data, script) { this.parent(data, script); } });
the response looks like:
{ "status": "ok", "results": [ { "types": [ "street_address" ],
but firebug reports 'invalid label' error @ '"status": "ok",\n'
anyone got idea how solve problem?
many thanks.
the reason is, googlemaps api has stopped serving jsonp , returns plain json (from gather).
what mootools is, send callback=request.jsonp.request_map.request_0
server should reply as:
request.jsonp.request_map.request_0({ "status": "ok" ... });
... is, if callback= not being ignored. since ignores it, response evaluated , 'run' simple json instead, producing invalid label exception.
anyway, recommend read how make cross-domain ajax calls google maps api? - seems js soltution viable here (aside script overhead)
Comments
Post a Comment