views:

381

answers:

1

Today I struggled with the following:

$.ajax({url:'http://maps.google.com/maps/api/geocode/jsonaddress=Karachi&sensor=false&output=json&callback=?',
        dataType: 'json',
        success: function(data){
         //eval("("+data+")");
         alert(data);
        }
});

Firefox gives the error "Invalid Label" and Chrome "Uncaught SyntaxError: Unexpected token :". I found a lot of posts about this, and I tried all kinds of things like eval(), but also:

$.getJSON('http://maps.google.com/maps/api/geocode/jsonaddress=Karachi&sensor=false&output=json&callback=?',
 function(data){
  //eval("("+data+")");
  alert(data);
 }
);

Same result. Also, other json data works fine, for instance flickr ("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?). So it has something to do with the Google Maps API output i guess..

Thanks in advance.

A: 

You just can't do it; AFAIK Geocoder V3 does not allow callback=?.
Check this thread for further information.

systempuntoout
Thanks for your reply, but Google DOES send back the JSON data. I can see it in Firebug. Also callback= is filled in, in my case: jsonp1271887454223. So that works..
Bennystijn
Anyway, I now fixed it with help of this tut: http://www.developer.com/db/article.php/10920_3621981_2/Performing-HTTP-Geocoding-with-the-Google-Maps-API.htm. It's kinda slow and xml instead of json, but works in my case. Thanks!
Bennystijn
@Benny JSON is returned but not wrapped in jsonp1271887454223() and firefox raises "invalid label" error.You could use callback but with V2 (deprecated) i think.
systempuntoout
Yeah, i think the tut i followed used v2.
Bennystijn