仅提供邮政编码的Google Maps API查询提供了不正确的结果 [英] Google Maps API query with only ZIP code provides incorrect results

查看:89
本文介绍了仅提供邮政编码的Google Maps API查询提供了不正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用Google Maps API,并且当用户输入5位数的邮政编码时,在大多数情况下结果都是正确的;它将输入视为邮政编码,并根据该位置返回结果.

We use the Google Maps API, and when a user inputs a 5 digit ZIP code, the results are correct the vast majority of the time; it treats the input as a ZIP code and returns results based on that location.

引起我们注意的问题是,查询某些邮政编码(42025是我们的主要示例)不会返回预期的结果(宾顿,肯塔基州). API调用实际上返回"status":"ZERO_RESULTS".在maps.google.com上进行类似的搜索有时会产生肯定的结果,但前提是肯塔基州本顿市已经消耗了大部分视口.一种解决方法是在查询字符串中添加术语"zip".

The problem that has come to our attention is that queries for certain ZIP codes (42025 is our prime example) does NOT return the expected results (Benton, KY). The API call actually returns "status":"ZERO_RESULTS". A similar search on maps.google.com will sometimes produce a positive result, but only if Benton, KY consumes a large portion of the viewport already. A workaround is to add the term "zip" in the query string.

我的调查表明,失败的结果似乎是使用5位数字的字符串,好像街道地址一样,什么都找不到.例如,对"42020"的查询最终显示的是华盛顿特区附近的某个地址.

My investigation has shown that the failed results appear to be using the 5 digit string as if a street address, which find nothing. A query for "42020" ends up showing some address near Washington D.C., for example.

有人遇到这个问题吗?有关如何解决此问题的任何建议?

Has anyone faced this issue? Any suggestions for how to address this?

推荐答案

我建议使用组件过滤以获取邮政编码.

I would suggest using a component filtering in your Geocoder requests in order to obtain postal codes.

您的请求将被重写为

https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A42025%7Ccountry%3AUS&key=YOUR_API_KEY

https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A42020%7Ccountry%3AUS&key=YOUR_API_KEY

两个请求都将预期结果返回给我.您还可以在Geocoder工具中看到它:

Both requests return expected results to me. You can also see it in the Geocoder tool:

我希望这会有所帮助!

这篇关于仅提供邮政编码的Google Maps API查询提供了不正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆