get formatted_address from google maps api json
30,699
Solution 1
Here's the corrected JS..
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);
}
});
Solution 2
data["results"][0]["formatted_address"]
Author by
lizart
Updated on February 20, 2020Comments
-
lizart about 4 years
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"
-
lizart over 10 yearsthank you, this solved my problem, ill accpect the answer in 4mins.
-
Daniel Cheeseman over 9 yearsThanks for this.. Just added to my code and worked perfectly!
-
Toniq about 7 yearsIs there a rule on how much is the length of formatted_address if I want to get specific address format?
-
Nikhil N about 7 years@Toniq not sure about the current version of api. You should check out latest documentation.