Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k 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 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...