Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

json - Parsing Google Geo API (Reverse Geocoding) with jQuery

I'm sure I'm not the only one, but I cannot parse/return anything when jQuery takes a request to lookup an address when the data being requested is the latitude and longitude so Google can return the data, but it cannot be read by jQuery?

http://maps.googleapis.com/maps/api/geocode/json

With parameters:

latlng=51.276914,1.077252
&sensor=false

In Firebug it says 200 OK but nothing is displayed in the response:

enter image description here

I can see it when I open it: http://maps.googleapis.com/maps/api/geocode/json?latlng=51.187296,1.229086&sensor=false&_=1302084865163

What I did was:

$.ajax(
{
    url: 'http://maps.googleapis.com/maps/api/geocode/json',
    data: 'latlng=' + geolocation + '&sensor=false',
    dataType: 'json',
    cache: false,
    success: function(data){ alert(data); }
});

That doesn't work... neither $.get, $.getJSON with the json dataType.

Why can't jQuery parse/read the response?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to use googles geocoder for security reasons. See answer here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...