如何从 GPS 坐标查找邮政编码?
假设我有一个 Web 服务 API,它接受邮政编码作为参数,但我只能访问 GPS 坐标(纬度、经度)。 如何动态查找坐标所属的邮政编码?
我正在 iPhone 上完成这项工作,因此希望有一种简单的方法可以在我在文档中忽略的 CoreLocation API 中完成这项工作。
Say I have a web service API that accepts a zipcode as a parameter, but I only have access to a GPS coordinate (latitude, longitude). How can I dynamically lookup the zipcode that the coordinate belongs to?
I'm doing this work on the iPhone, so hopefully there's a simple way to do this within the CoreLocation APIs that I'm overlooking in the documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此页面提供了美国所有邮政编码及其纬度和经度的数据库(csv 格式)。
http://zips.sourceforge.net/
该文件解压后大小为 500k。 这是前几行数据:
将此数据转储到本地数据库中。 使用半正弦公式将您的坐标与数据库中的坐标进行比较,以找到最近的点。 CoreLocation 有一个函数 getDistanceFrom 您也可以使用。
此页面有 c 语言的半正矢函数和有关 zips 数据库的信息。
http://www.jaimerios.com/?p=39
编辑:< /strong> 这是 Google 关于计算距离的精彩解释。 它使用 MySQL 和 PHP,但用于查找最近点的 SQL 在这里也很有用。 使用 SQL 查询可能比 getDistanceFrom 函数更快。
http://code.google.com/support/bin /answer.py?answer=87134&topic=11364
查找距离 37, -122 坐标 25 英里半径内最近的 20 个位置:
要按公里而不是英里进行搜索,请将 3959 替换为 6371。
This page provides a database (in csv) of all the zip codes in the US, with their latitude and longitude.
http://zips.sourceforge.net/
The file is 500k unpacked. Here's the first few lines of data:
Dump this data into a local database. Use the Haversine formula to compare your coordinates and the ones in the database to find the nearest point. CoreLocation has a function getDistanceFrom that you could use too.
This page has a Haversine function in c and info about the zips database.
http://www.jaimerios.com/?p=39
Edit: Heres a great explanation from Google about calculating distances. It uses MySQL and PHP, but the SQL for finding nearest points is also useful here. It'd probably be faster to query using SQL, rather than the getDistanceFrom function.
http://code.google.com/support/bin/answer.py?answer=87134&topic=11364
Find the closest 20 locations that are within a radius of 25 miles to the 37, -122 coordinate:
To search by kilometers instead of miles, replace 3959 with 6371.
如果我是你,我会尝试查看 3.0 SDK 中反向地理编码器的文档。 我不能说那里有什么,但您可能会发现反向地理编码返回一个 placeMark,然后如果您在 SDK 中查找该 placeMark,您可能会发现它有一个邮政编码属性。 谁知道?
I'd try checking out the docs for the reverse geocoder in the 3.0 SDK if I were you. I can't say what's there, but you might, say, find that the reverse geocode returns a placeMark, and then if you look up that placeMark in the SDK, you might find that it has a postcode property. Who knows?
这种查找称为“反向地理定位”。
您需要做的第一件事是将 lat/lng 数据从 CLocation 对象转换为度数...
在 locationManager 函数中(一旦收到位置更新就会调用该函数)...
代码:
从那里您发送 lat 和lng 字符串到后端网络服务,如“GeoNames.org”或 Google Maps API ...,您可以获得最近的城市或街道地址。
This kind of lookup is called "Reverse Geolocation."
The first thing you need to do is convert the lat/lng data from CLocation object to degrees...
in the locationManager function (which is called once you receive a location update)....
Code:
From there you send the lat and lng strings to a backend webservice like "GeoNames.org" or Google Maps API ... and you can get the nearest city or street address.
美国人口普查局制作了一个数据库——Tiger 数据库。 我相信有可能根据纬度/经度查找邮政编码。
我敢打赌,如果您搜索 Tiger 邮政编码 你可能会找到一些东西。 例如,请参阅此处。 看来 CPAN 上有一个 Perl 模块可以做到这一点,所以这应该不是不可能的。
There is a database produced by the US Census - the Tiger database. I believe there is a possibility to lookup zipcode given lat/long.
I'll bet if you searched for Tiger zipcode you might find something. see here for example. It appears there is a Perl module on CPAN that does this, so it shouldn't be impossible.
Google 提供免费的反向地理编码服务。 您可以直接使用它,或者尝试 Temboo SDK,它提供多种语言的便捷访问,包括 Objective C(带有代码示例)。
请查看 https://www.temboo.com/library/Library/Google/地理编码/通过坐标进行地理编码/
Google offers a free reverse-geocoding service. You can use it directly, or try the Temboo SDK which offers convenient access in multiple languages, including Objective C (with code samples).
Check out https://www.temboo.com/library/Library/Google/Geocoding/GeocodeByCoordinates/