本文介绍了结合使用jquery.getJson和Google的GeoCoding HTTP服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google提供了一个出色的REST接口,用于对地址进行地理编码和反向地理编码.我的API密钥有效,并且如果我直接在浏览器地址中输入请求,效果很好.但是,以下jquery失败很可怕,我没明白为什么.希望你能在这里帮助我.

Google offers a wonderful REST interface for geocoding and reverse geocoding an address. My API key is valid, and if I enter the request directly into the browser address it works great. However, the following jquery fails terrible and I'm failing to see why. Hoping you could help me out here.

$.getJSON("http://maps.google.com/maps/geo?q="+ address+"&key="+apiKey+"&sensor=false&output=json",
  function(data, textStatus){
     console.log(data);
  });

此服务的Google REST接口文档: http://code. google.com/apis/maps/documentation/geocoding/index.html

Google's REST interface doc for this service: http://code.google.com/apis/maps/documentation/geocoding/index.html

推荐答案

这里的问题是我没有指定JSONP回调.正确的代码如下

The problem here is that I wasn't specifying the JSONP callback. The correct code is as follows

$.getJSON("http://maps.google.com/maps/geo?q="+ address+"&key="+apiKey+"&sensor=false&output=json&callback=?",
  function(data, textStatus){
     console.log(data);
  });

这篇关于结合使用jquery.getJson和Google的GeoCoding HTTP服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:02