在google api v3中使用geo-autocomplete获取邮政编码 [英] Get zipcode with geo-autocomplete in google api v3
问题描述
这是我使用的代码: https:// google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete
当我在地理自动填充文本字段中选择一个地址时,我想让相应的邮政编码出现在另一个文本框中,这可能吗?我会很高兴如果有人可以帮助我达成解决方案。
经过一些研究,我发现这一点:
var zip = address [address.length - 1] .long_name = results [0] .address_components;
但我对如何使用此代码获取邮政编码感到困惑?
谢谢!
在我看来:
- 在该回复中不一定总是邮政编码。
- 如果有一个,获得它的最好方法是搜索通过查找类型为postal_code的结果的address_components并使用该结果,如此示例
-
This is the code I am using: https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete
When I select an address in the geo-autocomplete textfield, I want the corresponding zipcode to appear in another textfield, is this possible? I would be glad if someone can help me reach a solution.
After doing some research I found this:
var zip = address[address.length - 1].long_name = results[0].address_components;
But I am confused with how to use this code to get the zipcode?
Thanks!
Looks to me like:
- there is not necessarily always a postal code in that response.
- if there is one, the best way to get it is to search through the address_components of the result looking for one with the type "postal_code" and use that, like this example
这篇关于在google api v3中使用geo-autocomplete获取邮政编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!