我是'm using Google Map'的Geocode API来获取曼哈顿这个地址的lat,lng值: 123 Dr Martin Luther King Jr Blvd, New York, NY 10035, USA
我的初始查询如下所示:https://maps.google.com/maps/api/geocode/json?address=123%20mlk%20blvd
此查询不会返回我想要的地址,因此为了将结果过滤到仅在曼哈顿的那些我通过请求修改以包括组件过滤参数 locality:Manhattan
.
正如文档中所定义:https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
所以我的问题是 - 为什么这个网址:https://maps.google.com/maps/api/geocode/json?address=123%20mlk%20blvd&components=locality:Manhattan没有返回我想要的地址?
然而 - 使用组件过滤器 postal_code:10035
会返回我想要的地址:https://maps.google.com/maps/api/geocode/json?address=123%20mlk%20blvd&components=postal_code:10035
谢谢
1 回答
我认为您应该注意的主要细节是Google最近改变了组件过滤器的行为 . 此更改是在2018年1月15日进行的 . 该文档现在包含以下文本:
来源:https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
这意味着目前只有邮政编码和国家/地区继续严格执行组件过滤器 . 地理编码API中的组件过滤不再像以前那样严格 . 此更改解释了示例请求的行为 . 具有局部性的组件过滤器不严格,因此您得到不同的结果,而具有邮政编码的组件过滤器是严格的并且您得到预期的结果 .
如果您需要某个位置,则应将其包含在请求的
address
参数中,以使其不那么模糊 .例如 .
https://maps.googleapis.com/maps/api/geocode/json?address=123%20mlk%20blvd%20Manhattan&key=YOUR_API_KEY
您应该遵循以下网址提供的地理编码API的最佳做法:
https://developers.google.com/maps/faq#geocoder_queryformat https://developers.google.com/maps/documentation/geocoding/best-practices
我希望我的回答能解释你的疑惑!