gpt4 book ai didi

ios - 如何在没有互联网连接的情况下从位置获取地址

转载 作者:行者123 更新时间:2023-12-01 18:14:04 24 4
gpt4 key购买 nike

我正在开发一个应用程序,以在蜂窝数据关闭或未连接 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);
}
}

谢谢。

最佳答案

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

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

--- 更新 (作为问题更新)---

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

所以,你无法进行反向地理编码 没有互联网连接使用原生 iOS API .

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

关于ios - 如何在没有互联网连接的情况下从位置获取地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24532402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com