Google 提供了一个出色的 REST 接口(interface),用于对地址进行地理编码和反向地理编码。我的 API key 是有效的,如果我直接将请求输入到浏览器地址中,效果会很好。然而,下面的 jquery 失败得很厉害,我不明白为什么。希望你能在这里帮助我。
$.getJSON("http://maps.google.com/maps/geo?q="+ address+"&key="+apiKey+"&sensor=false&output=json",
function(data, textStatus){
console.log(data);
});
此服务的 Google REST 接口(interface)文档:http://code.google.com/apis/maps/documentation/geocoding/index.html
最佳答案
这里的问题是我没有指定 JSONP 回调。正确代码如下
$.getJSON("http://maps.google.com/maps/geo?q="+ address+"&key="+apiKey+"&sensor=false&output=json&callback=?",
function(data, textStatus){
console.log(data);
});
关于jquery - 将 jquery.getJson 与 Google 的地理编码 HTTP 服务结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/898201/