Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过ajax调用从json响应读取数据_Javascript_Jquery_Json_Ajax_Google Maps - Fatal编程技术网

Javascript 通过ajax调用从json响应读取数据

Javascript 通过ajax调用从json响应读取数据,javascript,jquery,json,ajax,google-maps,Javascript,Jquery,Json,Ajax,Google Maps,我正在做一个ajax调用,从pin码中获取经度和纬度 $(document).ready(function () { $.ajax({ type: "GET", url: "http://maps.googleapis.com/maps/api/geocode/json?address=753010,India&sensor=false", data: {},

我正在做一个
ajax
调用,从pin码中获取经度和纬度

$(document).ready(function () {
            $.ajax({
                type: "GET",
                url: "http://maps.googleapis.com/maps/api/geocode/json?address=753010,India&sensor=false",
                data: {},
                dataType:"json",
                success: function (results) {
                    console.log(results);
                    console.log(results.length);
                    //alert(results.geometry.location.lat);
                    //alert(results.geometry.location.lng);
                },
                error: function (ex) {
                    alert("Error");
                }
            });
        });
我得到的答复如下图所示

但是我不能通过使用这个
结果.geometry.location.lat来获得经度和纬度,我也尝试了
结果[0]

请帮助查找经度和纬度。另外,如果我没有错,请给出正确的经度和纬度。

根据:

当地理编码器返回结果时,它会将结果放入一个(JSON)results数组中。即使地理编码器不返回任何结果(例如,如果地址不存在),它仍然返回一个空的results数组

请注意,返回的JSON可能包含多个值,如果要捕获所有可能的值,最好在结果数组的长度上进行迭代。实际上,您可能只希望访问第一个结果
results[0]
位置


results.results[0].geometry.location.lat
results.results[0].geometry.location.lng
相应地。

它是
results.results[0].geometry.location
;)