【问题标题】:How to get address from location without Internet connection如何在没有互联网连接的情况下从位置获取地址
【发布时间】:2014-07-02 13:27:41
【问题描述】:

我正在开发一个应用程序,用于在蜂窝数据关闭或 WiFi 未连接时获取当前位置。

我使用了以下代码,但我得到的只有纬度和经度,没有带地址的位置。

所以我需要指导来实施它。

     - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
           NSLog(@"didUpdateToLocation: %@", newLocation);
            CLLocation *currentLocation1 = newLocation;

    if (currentLocation1 != nil)
     {
        strLet=[NSString stringWithFormat:@"%f",currentLocation1.coordinate.latitude];
        strLong=[NSString stringWithFormat:@"%f",currentLocation1.coordinate.longitude];
        NSLog(@"%f",currentLocation1.coordinate.longitude);
       NSLog(@"%f",currentLocation1.coordinate.latitude);
     }  
}

谢谢。

【问题讨论】:

  • “完美位置”是什么意思?
  • 查看有问题的变化
  • 您要的是纬度、经度(请参阅您的问题的标题),现在您声称您得到了纬度/经度,但还想要一个地址?
  • 您从该位置获取地址的代码在哪里?

标签: ios iphone location cllocation


【解决方案1】:

为了您的信息,通过使用 GPS,我们可以在没有有效互联网连接的情况下获取当前位置,但是它

(1) 需要很长时间才能获得位置,(2) 在建筑物或街道内无法正常工作

--- 更新(问题已更新)---

通过使用苹果的原生 iOS API,您可以使用 MKReverseGeocoder(在 MapKit 框架中提供)或 CLGeocoder(在 CoreLocation 框架中提供)进行反向地理编码。
但是,这需要有效的互联网连接才能从服务器获取数据。

因此,如果没有互联网连接使用原生 iOS API,您无法进行反向地理编码

但是,通过使用以下第三方库,您可以获得有限的可用地址信息(国家名称和 ISO 代码):
IOS-Offline-GeoCoder
ios-offline-reverse-geocode-country,

【讨论】:

  • 但它只返回纬度和经度,我可以在没有互联网连接的情况下从经度和纬度获取完整地址吗?
  • 我认为这可能是 GPS 的限制,因为我在 (2) 中提到的在建筑物或街道内无法正常工作....但是让我对其进行一些研究,我会正确回复您回答..
  • @ Nitesh Borad 和 Rakesh Thummar,你有完整的地址吗? 如果有,请分享你的代码。提前致谢。
  • 这是什么意思?上述答案的最后几行。 if (newLocation.horizo​​ntalAccuracy 20){返回; }
  • @Lydia:感谢您的关注。我已经删除了这些行,因为它们不是必需的。
猜你喜欢
  • 1970-01-01
  • 2013-09-11
  • 2017-09-09
  • 2013-02-17
  • 1970-01-01
  • 1970-01-01
  • 2018-01-31
  • 2017-08-25
  • 1970-01-01
相关资源
最近更新 更多