3

今天我遇到了以下问题:

$.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 给出错误“Invalid Label”和 Chrome “Uncaught SyntaxError: Unexpected token :”。我发现了很多关于这个的帖子,我尝试了各种各样的东西,比如 eval(),但也:

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

结果相同。此外,其他 json 数据也可以正常工作,例如 flickr (" http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback= ?)。所以它与我猜是谷歌地图 API 输出..

提前致谢。

4

2 回答 2

2

您可以在 maps V3 中执行此操作,但您不能使用 $.getJSON 来获取数据,相反,如果您给它一个地址,则 maps api 中有一个方法可以检索数据。

var  geocoder = new google.maps.Geocoder();
 geocoder.geocode( { 'address': '10 downing street, London, UK'}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        console.log(results);
        alert(results[0].geometry.location);

      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });

这些链接包含所有信息.... https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingRequests

https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple

于 2012-04-04T15:50:46.967 回答
0

你就是做不到;AFAIK Geocoder V3 不允许callback=?
检查线程以获取更多信息。

于 2010-04-21T21:40:53.783 回答