如何在iPhone上找到一个城市的经度和纬度?
我正在尝试在 iPhone 上查找城市的经度和纬度。假设用户正在搜索伦敦,我会调用一些函数来检索伦敦的经度和纬度。我在网上查了一下,发现你可以使用 Google API,但一定有 Apple 函数来处理这个问题?
我遇到过 MKReverseGeocoder,它可以获取经度和纬度,并告诉您您所在的城市附近。例如,
// reverse geocode the user location
geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];
如果它可以逆转该过程,则必须有某种形式的 MKGeocoder 类?
I am trying to find the long and lat of a city on the iphone. Say the user is searching for London, I would call some function that would retrieve the long and lat of London. I have looked on the web and found you can use a Google API but there must be an Apple function somewhere to handle this?
I have come accross the MKReverseGeocoder which takes the long and lat and tells you what city you are near. e.g.
// reverse geocode the user location
geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];
If it can reverse the process there must be some form of MKGeocoder class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么一定要有呢?因为没有。
您可以使用许多网络服务(例如 Google),或者您可以下载地名数据库,例如 http:// www.geonames.org/ 并将其导入到您的应用程序中。最好将其导入 SQL 数据库,然后您可以从应用程序中进行搜索。
Why must there be? Because there isn't.
There are a number of web services you can use (e.g. Google) or you could download a place name database such as http://www.geonames.org/ and import it into your app. It's probably best to import it into an SQL database which you can then search from your app.
请参阅 OpenStreetMap。它使您可以更灵活地访问其数据。您可以使用所需的信息预先填充 CoreData 存储。
有一些 api 客户端,即 route-me 或 cloudmade。
See OpenStreetMap. It gives you more flexibility in accessing its data. You could pre-populate a CoreData store with the informations you need.
There are some api-clients, i.e. route-me or cloudmade.
iOS5 SDK 添加了对正向和反向地理编码的支持。看看 CLGeocoder 类 类了解更多信息。
The iOS5 SDK has added support for both forward and reverse geocoding. Take a look at at the CLGeocoder class class for more info.
首先,放弃“必须有”苹果方式。确实没有。如果你不相信我和我近2k的经验值,听听Ole和他的13k经验值。
我见过三种服务。
我尝试了谷歌的地理编码API。它很不错,但有点复杂,而且它们会非常严格地限制你的查询。
然后我尝试了 MapQuest,我发现它非常出色。我有两个应用程序将在下个月左右发布到应用程序商店,它们使用 MapQuest 的 API。
然后我发现了 Geonames,它给我留下了深刻的印象,但还没有机会使用。请注意,Geonames 确实允许您下载其数据,因此如果您确实需要无网络服务,这可能是一个解决方案。
除此之外,您还将从设备上调用某些内容。顺便说一句,当您使用 MKReverseGeocoder 时,您就是这样的——这只是 Google 反向地理编码服务的包装器。
First, give up that there "must be" an Apple way. There really isn't. If you don't believe me and my nearly 2k of experience points, listen to Ole and his 13k.
There are three services I've seen.
I tried Google's geocoding API. It's decent, but a bit complicated, and they throttle your queries pretty harshly.
Then I tried MapQuest's, which I found to be surprisingly excellent. I have two apps bound for the app store in the next month or so that use MapQuest's API.
Then I found Geonames, which I'm very impressed by but haven't had the opportunity to use yet. Note that Geonames DOES allow you to download their data, so if you really need network-free service, this might be a solution.
Apart from that, you're going to be calling something off the device. Which, by the way, you are when you use MKReverseGeocoder--that's just a wrapper around Google's reverse geocoding service.