Google Maps Geocoding API - 国家偏见,奇怪的结果
我正在从 PHP 连接到 Google Maps API,以对租赁站定位器应用程序的一些起点进行地理编码。
这些起点不必是确切的地址;城市名称就足够了。使用准确度
等于或大于4(城市/地区级别)的地理编码响应作为起点,并搜索周围的租赁站。
该应用程序应该在德国运行。当地点名称不明确时(即该名称有多个地方),我想显示一系列可能性。
一般来说,这不是问题:如果您进行不明确的搜索,Google 的 XML 输出将返回一个
元素列表,而不是仅一个。
显然,我需要将地理编码偏向德国,因此如果有人输入其他国家/地区也存在的邮政编码或地点名称,实际上只会出现德国的匹配结果。
我认为可以通过在搜索查询中添加 , de
或 , Deutschland
来实现此目的。这在大多数情况下工作得很好,但在某些情况下会产生奇怪和难以忍受的结果。
例如,德国有 27 个地点名为 Neustadt
。 (Wikipedia)
当我单独搜索 Neustadt
时:
http://maps.google.com/maps/geo/hl=de&output=xml&key=xyz&q=Neustadt
我得到其中至少有六个,我可以接受(其他的可能没有合并,或者属于不同地点的一部分,或者其他什么)。
但是,当我搜索 Neustadt, de
或 Neustadt, Deutschland
或 Neustadt, German
时,我只得到一个< /em> 二十七个地点中,没有明显的原因 - 它不是最大的,也不是最准确
准确的,也没有任何其他独特的特征。
有谁知道这是为什么,我能做什么?
我尝试了 region
参数,但无济于事 - 当我不使用 , de
时,邮政编码(如 50825
将解析为美国对应的邮政编码) ,而不是德国的。
我当前的解决方法是在输入仅为数字时添加国家/地区名称,否则仅过滤掉德国结果,但这听起来非常混乱有人知道更好的方法吗?
I'm connecting to the Google Maps API from PHP to geocode some starting points for a rental station locator application.
Those starting points don't have to be exact addresses; city names are enough. Geocoding responses with an accuracy
equal to or grater than 4 (city/locality level) are used as starting points, and the surrounding rental stations searched.
The application is supposed to work in Germany. When a locality name is ambiguous (i.e. there are more than one place of that name) I want to display a list of possibilities.
That is not a problem in general: If you make an ambiguous search, Google's XML output returns a list of <PlaceMark>
elements instead of just one.
Obviously, I need to bias the geocoding towards Germany, so if somebody enters a postcode or the name of a locality that exists in other countries as well, only hits in Germany actually come up.
I thought I could achieve this by adding , de
or , Deutschland
to the search query. This works mostly fine, but produces bizarre and intolerable results in some cases.
There are, for example, 27 localities in Germany named Neustadt
. (Wikipedia)
When I search for Neustadt
alone:
http://maps.google.com/maps/geo/hl=de&output=xml&key=xyz&q=Neustadt
I get at least six of them, which I could live with (it could be that the others are not incorporated, or parts of a different locality, or whatever).
When, however, I search for Neustadt, de
, or Neustadt, Deutschland
, or Neustadt, Germany
, I get only one of the twenty-seven localities, for no apparent reason - it is not the biggest, nor is it the most accuracy
accurate, nor does it have any other unique characteristics.
Does anybody know why this is, and what I can do about it?
I tried the region
parameter but to no avail - when I do not use , de
, postcodes (like 50825
will be resolved to their US counterparts, not the german ones.
My current workaround idea is to add the country name when the input is numeric only, and otherwise filter out only german results, but this sounds awfully kludgy. Does anybody know a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这绝对不是一个详尽的答案,只是一些注释:
您正在使用Geocoding API 的旧 V2 版本,Google 最近已弃用该版本,转而使用新的 V3 API。谷歌建议从现在开始使用新服务,虽然我对新版本没有真正的经验,但他们似乎在各个方面改进了服务,特别是响应的结构。您不需要 API 密钥即可使用新服务,只需使用稍微不同的 URL:
<块引用>
http://maps.google.com /maps/api/geocode/xml?address=Neustadt&sensor=false
您提到您正在根据其准确性属性过滤地标。请注意,该字段不再出现在新的 Geocoding API 的结果中,但无论如何,我认为它在旧的 API 中仍然不太可靠。
您可能想尝试使用新 API 的
bounds
和region
参数,但我仍然怀疑它们能否解决您的问题。我相信,当您以至少“街道、地区、国家”格式提供完整地址时,Google 地理编码器是一个很棒的工具,并且当它不需要处理任何其他格式时,它也非常可靠。歧义(地理编码“英国伦敦”总是对我有用)。
但是,就您而言,我确实会考虑预先计算每个德国地区的所有坐标,并在数据库中自行处理地理编码。我认为这是非常可行的,特别是因为您的应用程序仅本地化到一个国家/地区。 维基百科“德国城镇列表” 中的每个城镇似乎都将坐标存储在一个整齐的列表中小
看起来很容易解析:
该列表中有 16 个诺伊施塔特,这可能比 Google 的 6 个更好:)
This is definitely not an exhaustive answer, but just a few notes:
You are using the old V2 version of the Geocoding API, which Google have recently deprecated in favour of the new V3 API. Google suggests to use the new service from now on, and while I have no real experience with the new version, it seems that they have improved the service on various points, especially with the structure of the response. You do not need an API key to use the new service, and you simply need to use a slightly different URL:
You mentioned that you were filtering for placemarks on their accuracy property. Note that this field does not appear anymore in the results of the new Geocoding API, but in any case, I think it was still not very reliable in the old API.
You may want to try to use the
bounds
andregion
parameters of the new API, but I still doubt that they will solve your problem.I believe that the Google Geocoder is a great tool for when you give it a full address in at least a "street, locality, country" format, and it is also very reliable in other formats when it doesn't have to deal with any ambiguities (Geocoding "London, UK" always worked for me).
However, in your case, I would really consider pre-computing all the coordinates of each German locality and simply handle the geocoding yourself from within your database. I think this is quite feasible especially since your application is localized to just one country. Each town in the Wikipedia "List of German Towns" appears to have the coordinates stored inside a neat little
<span>
which looks very easy to parse:There are sixteen Neustadts in that list, which may be better than Google's six :)
发现 google 自动完成功能比其地理编码效果更好
http://code.google .com/apis/maps/documentation/javascript/places.html#places_autocomplete
found google autocomplete works better then their geocode
http://code.google.com/apis/maps/documentation/javascript/places.html#places_autocomplete
发现这个问题正在寻找这个确切的问题。然后意识到 Bing Maps API 的效果要好得多。但它有其怪癖。例如,如果您传递一个机场代码,它会显示 6 个不同的解决方案,每个解决方案对应于机场的每个航站楼。
Found this question searching for this exact issue. Then realized Bing Maps API works much better. It has its quirks though. For example, if you pass an airport code, it would show you 6 different solutions, each corresponding to each terminal of the airport.