get formatted_address from google maps api json

夙愿已清 提交于 2019-12-10 09:24:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!