Google地图地理编码API - 国家/地区偏差,奇怪的结果 [英] Google Maps Geocoding API - country biasing, bizarre results

查看:139
本文介绍了Google地图地理编码API - 国家/地区偏差,奇怪的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从PHP连接到Google Maps API,为出租站定位器应用程序的地理编码起点。



这些起点不一定非要确切地址;城市名称就够了。以准确度等于或大于4(城市/地区级别)的地理编码响应被用作出发点,并搜索周围的租赁站点。

该应用程序应该在德国工作。当地区名称不明确时(例如,该名称不止一个地方),我想显示一个可能性列表。



这通常不是问题:如果您进行模糊搜索,则Google的XML输出将返回< PlaceMark> 元素的列表,而不仅仅是一个。



<显然,我需要将地理编码偏向德国,所以如果有人输入邮编或其他国家的地区名称,只有德国的点击才会真正出现。



我想我可以通过在搜索查询中添加,de ,Deutschland 来实现。这在很大程度上是正常的,但在某些情况下会产生奇怪和不可容忍的结果。

例如,德国有27个地方叫做 Neustadt code>。 ( Wikipedia



当我仅搜索 Neustadt

  http://maps.google。 com / maps / geo / hl = de& output = xml& key = xyz& q = Neustadt 

我至少得到了其中的六个,我可以与之共存(可能是其他人没有被合并,或者是不同地方的某个部分,或者其他)。

但是,当我搜索 Neustadt,de Neustadt,Deutschland Neustadt ,德国,我只得到27个地区中的一个,因为没有明显的原因 - 它不是最大的,也不是最多的准确性准确,也没有任何其他独特的特征。

有人知道这是为什么,我能做些什么吗? / p>

我尝试了区域参数,但无济于事 - 当我不使用时,de ,邮编(例如 50825 )将解决给他们的美国同行,而不是德国人。



我当前的解决方法是在输入数字时只添加国家名称,否则只会过滤德国的结果,但这听起来非常糟糕。有人知道更好的方法吗?

解决方案

这绝对不是一个详尽的答案,只是几个注释:


  1. 您正在使用旧版V2的Geocoding API ,Google最近弃用了新的V3 API 。谷歌建议从现在开始使用新服务,尽管我对新版本没有真正的体验,但似乎他们已经改进了各种服务,特别是响应结构。您不需要API密钥来使用新服务,而只需使用稍微不同的URL: http://maps.google.com/maps/api/geocode/xml?address=Neustadt&sensor=false =nofollow noreferrer> http://maps.google.com/maps/api/geocode/ xml?address = Neustadt& sensor = false


  2. 您提到您正在筛选地标的准确性属性。请注意,此字段不会再出现在新的Geocoding API的结果中,但在任何情况下,我认为它在旧API中仍然不太可靠。


  3. 您可能想尝试使用新API的界限区域参数,但我仍然怀疑他们会解决您的问题。

  4. 我相信Google Geocoder是一个很棒的工具,至少在一个街道,地区,国家格式的完整地址,当它不需要处理任何含糊不清的情况时(格伦代码伦敦,英国总是为我工作),它在其他格式中也非常可靠。然而,就你而言,我真的会考虑预先计算每个德国地区的所有坐标,并简单地在数据库中处理自己的地理编码。我认为这是非常可行的,特别是因为你的应用程序本地化到一个国家。 维基百科德国城镇名单中的每个城镇似乎都有一个整齐的坐标< span> 这看起来很容易分析:

     << ; span class =geo> 47.84556; 8.85167< /跨度> 

    该列表中有十六个Neustadts,可能比Google的六个要好:)


    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?

    解决方案

    This is definitely not an exhaustive answer, but just a few notes:

    1. 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:

      http://maps.google.com/maps/api/geocode/xml?address=Neustadt&sensor=false

    2. 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.

    3. You may want to try to use the bounds and region 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:

    <span class="geo">47.84556; 8.85167</span>
    

    There are sixteen Neustadts in that list, which may be better than Google's six :)

    这篇关于Google地图地理编码API - 国家/地区偏差,奇怪的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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