问题
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"
回答1:
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);
}
});
回答2:
data["results"][0]["formatted_address"]
来源:https://stackoverflow.com/questions/19398702/get-formatted-address-from-google-maps-api-json