简体   繁体   English

谷歌地图从latLng获取邮政编码

[英]google map get postal code from latLng

been trying find a way to extract postcode from latlng position but im not entirely sure how to do it. 一直试图找到一种从latlng位置提取邮政编码的方法,但我不确定如何做到。 can someone point me to the right direct please, im using google api autocomplete. 有人可以将我指向正确的直接位置吗,即时通讯使用google api自动完成功能。

I tried using address_components but it only gives me short/long names and types. 我尝试使用address_components,但它只给我提供了短/长名称和类型。

You will need to use another service for this. 您将需要使用其他服务。 postcodes.io is free, open source and uses open data. postcodes.io是免费的开放源代码,并使用开放数据。 The request you are looking for is: 您正在寻找的要求是:

GET api.postcodes.io/postcodes?lon=:longitude&lat=:latitud e GET api.postcodes.io/postcodes?lon=:longitude&lat=:latitud e

Get the long lat from google maps and then make a separate request to a postcode service to get the postcode you are looking for. 从Google地图获取较长的纬度,然后向邮递服务单独发出请求,以获取所需的邮编。

The service above covers UK postcodes only. 上面的服务仅涵盖英国邮政编码。 You may need to use multiple services for different countries. 您可能需要为不同的国家/地区使用多种服务。

See this related question on GIS Stack Exchange 在GIS Stack Exchange上查看相关问题

if the data returned were called "addresses"... 如果返回的数据称为“地址” ...

var arr = addresses.results[0].address_components,
    i = 0,
    len = arr.length;
for (i; i < len; i++) {
    if (arr[i].types[0] === "postal_code") {
        alert(arr[i].long_name)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM