如何以编程方式(合法地)获取街道地址的经度和纬度
据说,可以从谷歌地图或某些此类服务中获取此信息。 (仅美国地址是不够的。)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
据说,可以从谷歌地图或某些此类服务中获取此信息。 (仅美国地址是不够的。)
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(15)
您正在寻找的术语是地理编码,是的,谷歌确实提供了这项服务。
新 V3 API:http://code. google.com/apis/maps/documentation/geocoding/
旧版 V2 API:http://code.google.com/apis/maps/documentation/services.html#Geocoding
The term you're looking for is geocoding and yes Google does provide this service.
New V3 API: http://code.google.com/apis/maps/documentation/geocoding/
Old V2 API: http://code.google.com/apis/maps/documentation/services.html#Geocoding
除了前面提到的 Google 地理编码网络服务之外,还有雅虎提供的竞争服务。 在最近的一个通过用户交互完成地理编码的项目中,我添加了对两者的支持。 原因是我发现,特别是在美国以外,他们对更不起眼的地点的处理差异很大。 有时谷歌会提供最佳答案,有时雅虎会提供最佳答案。
需要注意的一个问题是:如果 Google 确实认为他们不知道你的位置在哪里,他们将返回 602 错误,表明失败。 另一方面,雅虎如果可以从您的错误地址中剔除城市/省/州/等,则会返回该城镇中心的位置。 所以你必须注意你得到的结果,看看它们是否真的是你想要的。 某些结果中的辅助字段可以告诉您这一点:雅虎称此字段为“精确度”,谷歌称其为“准确性”。
In addition to the aforementioned Google geocoding web service, there is also a competing service provided by Yahoo. In a recent project where geocoding is done with user interaction, I included support for both. The reason is I have found that, especially outside the U.S., their handling of more obscure locations varies widely. Sometimes Google will have the best answer, sometimes Yahoo.
One gotcha to be aware of: if Google really thinks they don't know where your place is, they will return a 602 error indicating failure. Yahoo, on the other hand, if it can peel out a city/province/state/etc out of your bad address, will return the location of the center of that town. So you do have to pay attention to the results you get to see if they are really what you want. There are ancillary fields in some results that tell you about this: Yahoo calls this field "precision" and Google calls it "accuracy".
如果您想在不依赖服务的情况下执行此操作,请下载 TIGER来自美国人口普查的 Shapefile。
您查找您感兴趣的街道,该街道有多个路段。 每个线段都有一个起始地址和结束地址,您可以沿着线段进行插值以找到您的门牌号位于线段上的位置。
这将为您提供经/纬度对。
但请记住,在线服务需要进行大量的地址检查和更正,您还必须重复这些操作才能获得良好的结果。
另请注意,尽管免费数据很好,但它并不完美 - 最新的街道不在那里(它们可能在谷歌使用的数据中),并且由于调查不准确,街道可能会偏离其真实位置一定程度。 但对于 98% 的地理编码需求,它可以完美运行,而且是免费的,并且您可以控制一切,因此可以减少应用程序中的依赖项。
Openstreetmaps 的目标是绘制世界上所有事物的地图,尽管他们还没有完全实现这一点,但值得密切关注,因为他们根据 CC 许可证提供数据。
但是,许多(大多数?)其他国家/地区仅由政府或服务绘制地图您需要为此付费。 如果您不需要对大量数据进行地理编码,那么使用 Google、Yahoo 或其他一些免费的全球地图服务可能就足够了。
如果您必须对大量数据进行地理编码,那么从主要提供商(例如 teleatlas)租赁地图数据将是您的最佳选择。
-亚当
If you want to do this without relying on a service, then you download the TIGER Shapefiles from the US Census.
You look up the street you're interested in, which will have several segments. Each segment will have a start address and end address, and you interpolate along the segment to find where on the segment your house number lies.
This will provide you with a lon/lat pair.
Keep in mind, however, that online services employ a great deal of address checking and correction, which you'd have to duplicate as well to get good results.
Also note that as nice as free data is, it's not perfect - the latest streets aren't in there (they might be in the data Google uses), and the streets may be off their real location by some amount due to survey inaccuracies. But for 98% of geocoding needs it works perfectly, is free, and you control everything so you're reducing dependencies in your app.
Openstreetmaps has the aim of mapping everything in the world, though they aren't quite there it's worth keeping tabs on as they provide their data under a CC license
However, many (most?) other countries are only mapped by gov't or services for which you need to pay a fee. If you don't need to geocode very much data, then using Google, Yahoo, or some of the other free worldwide mapping services may be enough.
If you have to geocode a lot of data, then you will be best served by leasing map data from a major provider, such as teleatlas.
-Adam
您还可以尝试 OpenStreetMap NameFinder,其中包含(可能)整个世界的开源、类似 wiki 的街道数据。 NameFinder 将在 8 月底停止存在,但 Nominatim 是其替代品。
You could also try the OpenStreetMap NameFinder, which contains open source, wiki-like street data for (potentially) the entire world. NameFinder will cease to exist at the end of august, but Nominatim is its replacement.
Google 要求您显示包含其数据的 Google 地图,每天最多有 2.5k(以前是 25k)HTTP 请求。 有用,但你必须注意使用。
他们确实有
http://groups.google.com/group/Google-Maps-API/web/resources-non-google-geocoders
(Google 已删除此内容。如果您看到重复或缓存,我会链接到那个。)
...我发现 GeoNames 它既有可下载的数据库,又有免费的网络服务和商业网络服务。
Google requires you to show a Google map with their data, with a max of 2.5k (was 25k) HTTP requests per day. Useful but you have to watch usage.
They do have
http://groups.google.com/group/Google-Maps-API/web/resources-non-google-geocoders
(Google has since removed this. If you see a duplicate or cache, I'll link to that.)
...in which I found GeoNames which has both a downloadable db, free web service and a commercial web service.
如果您的网站可供消费者免费使用,Google 的服务条款将允许您免费使用其地理编码 API。 如果没有,您将必须获得企业地图的许可证。
Google's terms of service will let you use their geocoding API for free if your website is in turn free for consumers to use. If not you will have to get a license for the Enterprise Maps.
与 Drupal 和 PHP 一起使用(并且易于修改):
For use with Drupal and PHP (and easily modified):
您可以在此处查看 Google Maps API 文档以开始使用:
http://code.google.com/apis/maps/documentation/services.html#Geocoding
您似乎也可以使用实时地图对国际地址执行以下操作:
http://virtualearth.spaces.live.com/blog/cns!2BBC66E99FDCDB98!1588。条目
You can have a look at the Google Maps API docs here to get a start on this:
http://code.google.com/apis/maps/documentation/services.html#Geocoding
It also seems to be something that you can do for international addresses using Live Maps also:
http://virtualearth.spaces.live.com/blog/cns!2BBC66E99FDCDB98!1588.entry
您还可以使用 Microsoft 的 MapPoint Web 服务来完成此操作。
这是一篇博客文章,解释了如何操作:
http://www.codestrider.com/BlogRead。 aspx?b=b5e8e275-cd18-4c24-b321-0da26e01bec5
You can also do this with Microsoft's MapPoint Web Services.
Here's a blog post that explains how:
http://www.codestrider.com/BlogRead.aspx?b=b5e8e275-cd18-4c24-b321-0da26e01bec5
用于获取街道地址的纬度和经度的 R 代码
R Code to get the latitude and longitude of a street address
如果您想在 Python 中执行此操作:
请注意,如果 Google 看到超过一定数量的请求,它似乎会限制请求,因此您确实希望在 HTTP 请求中使用 API 密钥。
If you want to do this in Python:
Note that Google does seem to throttle requests if it sees more than a certain amount, so you do want to use an API key in your HTTP request.
我有一批 100,000 条记录需要进行地理编码,并遇到了 Google API 的限制(由于它是针对内部企业应用程序,我们必须升级到他们的高级服务,价值 1 万美元以上),
所以,我使用了这个:http://geoservices.tamu.edu/Services/Geocode/BatchProcess/ - 他们还有一个API。 (总成本约为200美元左右)
I had a batch of 100,000 records to be geocode and ran into Google API's limit (and since it was for an internal enterprise app, we had to upgrade to their premium service which is $10K plus)
So, I used this instead: http://geoservices.tamu.edu/Services/Geocode/BatchProcess/ -- they also have an API. (the total cost was around ~200$)
您可以在 JavaScript 中针对城市尝试此操作,例如 kohat
You can try this in JavaScript for city like kohat
在Python中使用 geopy PyPI 用于获取纬度、经度、邮政编码等。
这是工作示例代码..
在 Nominatim 中 - 有些地址无法工作,所以我只是尝试 MapQuest。
它正确返回。
Mapquest 每月提供 15000 笔交易的免费计划。 对我来说就足够了。
示例代码:
希望有帮助。
In python using geopy PyPI used to get the lattitude,langitude,zipcode etc..
Here is the working sample code..
In Nominatim - Some addresses can't working, so i just tried MapQuest.
It returns correctly.
Mapquest provides free-plan 15000 transactions/month. It is enough for me.
Sample code:
Hope it helps.
我知道这是一个老问题,但谷歌改变了定期获取纬度和经度的方式。
HTML 代码
JavaScript 代码
I know this is old question but google changing way to get latitude and longitude on regular based.
HTML code
JavaScript Code