尝试从Google map api获取JSON对象时,使用$ .ajax获取错误

时间:2010-08-13 11:28:23

标签: jquery ajax

我正在尝试使用ajax和jquery从google map api获取json。

代码类似于

     url: "('http://maps.google.com/maps/api/geocode/json?address=559/1,+9th cross+7th main+Gokula,+1st stage+bangalore,+Karnataka,+India&sensor=false')",
     type: "POST",
     dataType: "jsonp",
     success: function(longlatJson) {
         var jsonObj = JSON.parse(JSON.stringify(longlatJson));

         var lat = jsonObj.results[0].geometry.location.lat;
         var long = jsonObj.results[0].geometry.location.lng;
         var latlng = new google.maps.LatLng(lat, long);

         map.panTo(latlng);
                 },

我未能得到结果。我的意思是它来自成功功能。

任何人都可以帮我解决这个问题吗?

此致 马赫什

1 个答案:

答案 0 :(得分:0)

我首先会提到这一点,因为它确实胜过了GeoEncode服务V3中的所有其他问题Google removed JSONP support,所以你不能像你正在尝试的那样发出跨域请求。< / p>

我看到这些是其他问题:

  • 没有理由对应该已经是对象的响应进行编码/解码(jQuery正在这里做工作)。
  • 您的网址包含在('')中,应删除这些网址。
  • 您错过了一个API密钥&key=somethinghere,我不确定缺少什么行为,因为我没有像这样使用谷歌服务。