Luke
Luke

Reputation: 3046

get and parse JSON with jquery from gmaps to find coordinates

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 :)

Upvotes: 3

Views: 4309

Answers (1)

Jusso
Jusso

Reputation: 121

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.

Upvotes: 2

Related Questions