Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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 从经纬度谷歌api获取邮政编码_Javascript_Jquery_Ajax_Google Maps - Fatal编程技术网

Javascript 从经纬度谷歌api获取邮政编码

Javascript 从经纬度谷歌api获取邮政编码,javascript,jquery,ajax,google-maps,Javascript,Jquery,Ajax,Google Maps,我只需要知道如何从经度和纬度获取邮政编码 我正在使用谷歌地图api,根据诸如“manchester”之类的搜索获取long和lat,然后我需要一个从中获取邮政编码以查询我的数据库 到目前为止,我的代码是 function getLatLng() { var localSearch = new google.maps.Geocoder(); var postcode = $("#address").val(); localSearch.geocode({ 'address'

我只需要知道如何从经度和纬度获取邮政编码

我正在使用谷歌地图api,根据诸如“manchester”之类的搜索获取long和lat,然后我需要一个从中获取邮政编码以查询我的数据库

到目前为止,我的代码是

function getLatLng()
{
    var localSearch = new google.maps.Geocoder();
    var postcode = $("#address").val();
    localSearch.geocode({ 'address': postcode },
                    function(results, status) {
                        if (results.length == 1) {
                            var result = results[0];
                            var location = result.geometry.location;
                        }
                        else 
                        {
                            $("#error").html("Address not found");
                        }
                    });
}

你想做的是(一个“反向地理编码”的例子)

见:

特别是链接到:


首先,您应该知道,在搜索“曼彻斯特”时,您可以将邮政编码与纬度和经度一起获得。看看这个。退房,你可以从那里得到邮政编码

或者,如果您想运行另一个查询,从您拥有的坐标中获取邮政编码(这似乎没有什么用处,因为正如我所说的,您可以在一次调用API中完成这项工作),您可以按照Geert Jan的建议进行反向地理编码

。。搜索如“manchester”,然后我需要a来获取邮政编码

您可能需要考虑:-

世界上有不止一个“曼彻斯特”

英国的“曼彻斯特”有许多邮政编码;地理编码可能只提供其中一个,如果查询过于笼统,则不提供任何一个

显然,由于邮局许可证问题,返回的英国邮政编码可能是零碎的-只有最重要的部分被返回