如何在iPhone上找到一个城市的经度和纬度?

发布于 2024-09-27 15:35:30 字数 393 浏览 2 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梨涡少年 2024-10-04 15:35:30

但必须有一个 Apple 函数来处理这个问题

为什么一定要有呢?因为没有。

您可以使用许多网络服务(例如 Google),或者您可以下载地名数据库,例如 http:// www.geonames.org/ 并将其导入到您的应用程序中。最好将其导入 SQL 数据库,然后您可以从应用程序中进行搜索。

but there must be an Apple function somewhere to handle this

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.

一笑百媚生 2024-10-04 15:35:30

请参阅 OpenStreetMap。它使您可以更灵活地访问其数据。您可以使用所需的信息预先填充 CoreData 存储。
有一些 api 客户端,即 route-mecloudmade

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.

尐籹人 2024-10-04 15:35:30

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.

披肩女神 2024-10-04 15:35:30

首先,放弃“必须有”苹果方式。确实没有。如果你不相信我和我近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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文