【发布时间】:2016-02-09 18:26:51
【问题描述】:
我正在使用 google maps api 来检查用户添加的地址,方法是传递邮政编码并返回一个格式化的地址,我可以比较它是否匹配。 这是电话:
resultNodeList = (NodeList) xpath.evaluate("/GeocodeResponse/result/formatted_address", geocoderResultDocument, XPathConstants.NODESET)
问题是某些邮政编码可能是多个城市/城镇的一部分。 这是邮政编码 77380 的 google api 的结果:
<GeocodeResponse>
<status>OK</status>
<result>
<type>postal_code</type>
<formatted_address>Spring, TX 77380, USA</formatted_address>
<address_component>
<long_name>77380</long_name>
<short_name>77380</short_name>
<type>postal_code</type>
</address_component>
<address_component>
<long_name>Spring</long_name>
<short_name>Spring</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Texas</long_name>
<short_name>TX</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United States</long_name>
<short_name>US</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>...</geometry>
<postcode_locality>Shenandoah</postcode_locality>
<postcode_locality>Spring</postcode_locality>
<postcode_locality>The Woodlands</postcode_locality>
<place_id>ChIJUXEWvwI0R4YRWJe_Gb6C8Bk</place_id>
</result>
</GeocodeResponse>
此示例中的用户居住在 Woodlands TX,而不是 Spring TX。 我现在要做的是拉入 postcode_locality 以便我可以比较列出的任何城市/城镇(Shenandoah、Spring、The Woodlands)
我厌倦了这样做:
resultNodeList = (NodeList) xpath.evaluate("/GeocodeResponse/result/postcode_locality", geocoderResultDocument, XPathConstants.NODESET);
但我只回来了雪兰多。 我可以执行 /GeocodeResponse/result/postcode_locality[1] 并手动获取每个位置,但此代码需要适用于输入的任何邮政编码。
有没有办法拉入 postcode_locality 列表?
【问题讨论】:
标签: java google-maps google-geocoding-api