Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  150] [ 2]  / answers: 1 / hits: 31959  / 11 Years ago, wed, october 16, 2013, 12:00:00

I want to get the formatted_adress from the json array.
an example link could be http://maps.googleapis.com/maps/api/geocode/json?latlng=55.397563, 10.39870099999996&sensor=false



var url = http://maps.googleapis.com/maps/api/geocode/json?latlng=+latlng+&sensor=false;
$.getJSON(url, function(data) {
var adress = data['formatted_address'];
alert(adress);
});


but im getting undefined


More From » jquery

 Answers
24

Here's the corrected JS..



Demo Fiddle



var latlng = 55.397563, 10.39870099999996;
var url = http://maps.googleapis.com/maps/api/geocode/json?latlng= + latlng + &sensor=false;
$.getJSON(url, function (data) {
for(var i=0;i<data.results.length;i++) {
var adress = data.results[i].formatted_address;
alert(adress);
}
});

[#74956] Tuesday, October 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
calicinthias

Total Points: 447
Total Questions: 101
Total Answers: 118

Location: Botswana
Member since Sat, Dec 31, 2022
1 Year ago
calicinthias questions
Sun, Jan 2, 22, 00:00, 2 Years ago
Wed, Jan 13, 21, 00:00, 3 Years ago
Mon, Aug 10, 20, 00:00, 4 Years ago
;