Google地图地理编码api不一致 [英] Google Maps geocode api inconsistencies

查看:135
本文介绍了Google地图地理编码api不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图对这个地址进行地理编码188th street& third avenue,bronx NY

如果您通过maps api v3 geocoder运行此地理编码查询,你会得到10个左右的结果,其中没有一个是在纽约。



http://maps.google.com/maps/api/geocode/xml? sensor = false& address = 188th%20street%20&%20ird%20avenue,%20bronx%20NY

如果您将同一个地址粘贴到Google地图中,它会直接到达Bronx交叉点。



这些结果有不一致的原因吗?有没有办法让地理编码器给我正确结果,或至少是在同一状态?

(起初我以为是因为'第三'被拼写出来,所以我用'3rd'取而代之。我在纽约市还有一个结果,其中一个在纽约皇后而不是布朗克斯。)

解决方案

问题是,您不需要URL编码& 在地址中并按原样使用它。但是这个& 用于分隔URL参数,例如介于 sensor = false& address = 之间。因此,超出& 的数据不被视为地址的一部分。你需要用地址参数中的& 替换它的URL编码%26



http://maps.google.com/maps/api/geocode/xml?sensor=false&address=188th%20street%20%26%20third%20avenue,%20bronx%20NY



你会在纽约,布朗克斯获得一个正确的位置:

 <地点> 
< lat> 40.8588700< / lat>
< lng> -73.8911250< / lng>
< / location>

仅供参考: Google地理编码网络服务在地址中使用 + 作为空格。另外,推荐的服务网址是 http://maps.googleapis.com/maps/api/geocode/ 。因此,您可以发出以下查询:



http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=188+street,% 26 +第三+大道,+布朗克斯+纽约



这看起来有点简单。


I'm trying to geocode this address "188th street & third avenue, bronx NY"

If you run this geocode query through the maps api v3 geocoder, you get back 10 or so results, none of which are in new york.

http://maps.google.com/maps/api/geocode/xml?sensor=false&address=188th%20street%20&%20third%20avenue,%20bronx%20NY

If you paste that same address into google maps, it takes you directly to the intersection in the bronx.

Is there a reason these results are inconsistent, and is there a way I can get the geocoder to give me the correct result, or at least something in the same state?

(at first i thought it was because 'third' was spelled out, so i replaced it with '3rd'. I still got 10 results with one in NYC. however, it was in queens instead of the bronx.)

解决方案

The problem is that you do not URL-encode & in the address and use it as it is. But this & is used for separation of URL arguments as e.g. between sensor=false&address=. So, the data beyond & is not considered to be part of the address. You need to replace & in the address argument by its URL-encoding %26:

http://maps.google.com/maps/api/geocode/xml?sensor=false&address=188th%20street%20%26%20third%20avenue,%20bronx%20NY

and you will get the one correct location in New York, Bronx:

<location>
    <lat>40.8588700</lat> 
    <lng>-73.8911250</lng> 
</location>

Just for information: the Google geocoding web service uses + for spaces in the address. Also, the recommended service URL is http://maps.googleapis.com/maps/api/geocode/. So, you could issue as well the query:

http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=188+street,%26+third+avenue,+bronx+NY

which appears a bit simpler.

这篇关于Google地图地理编码api不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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