3

i wanna parse a json like this http://maps.google.com/maps/api/geocode/json?address=milano&sensor=false only to find the latitude and longitude of an address (in this case is milano).

anyone can help me? thanks a lot in advance :)

1 Answer 1

2

A quick and dirty way:

$.getJSON('http://maps.google.com/maps/api/geocode/json?address=milano&sensor=false',function(data) {
    var location = data.results[0].geometry.location;
    // coordinates are location.lat and location.lng
});

This gets the coordinates for the first result. It might not be the result you are looking for, but it's trivial to iterate through the results to find the right one.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks jusso, but i get a "TypeError: Result of expression 'data' [null] is not an object." in the console!
It seems that google doesn't support JSONP anymore, so I don't know of a way to overcome the crossdomain limitation. Maybe you should just use the full google maps JS api?
yeah you're right, just tried this $.getJSON("maps.google.com/maps/…?", function(data, textStatus){ console.log(data); }); and it seems to work...the structure of the json is different, can you explain me how can i parse this one? thanks a lot!
data.Placemark[0].Point.coordinates contains the coordinates in an array. [0] and [1] seem to be latitude and longitude.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.