Ios 如何在没有internet连接的情况下获取用户位置

Ios 如何在没有internet连接的情况下获取用户位置,ios,iphone,objective-c,gps,Ios,Iphone,Objective C,Gps,我需要获得用户的纬度和经度,即使iOS中没有互联网设施 注意:没有互联网,没有蜂窝网络和蜂窝服务。在@implementation中添加以下变量: CLLocationManager *manager; CLGeocoder *geocoder; 在您的viewDidLoad中: manager = [[CLLocationManager alloc] init]; geocoder = [[CLGeocoder alloc] init]; manager.delegate = self; m

我需要获得用户的纬度和经度,即使iOS中没有互联网设施


注意:没有互联网,没有蜂窝网络和蜂窝服务。在@implementation中添加以下变量:

CLLocationManager *manager;
CLGeocoder *geocoder;
在您的viewDidLoad中:

manager = [[CLLocationManager alloc] init];
geocoder = [[CLGeocoder alloc] init];
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
[manager startUpdatingLocation];
然后添加以下方法:

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    geolocerror = YES;
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    CLLocation *currentLocation = newLocation;
    if (currentLocation != nil) {
        NSLog([NSString stringWithFormat:@"Lat: %.8f", currentLocation.coordinate.latitude]);
        NSLog([NSString stringWithFormat:@"Long: %.8f", currentLocation.coordinate.longitude]);
    }
}
别忘了在框架中添加CoreLocation。

看看

核心位置框架允许您确定当前位置或位置 与设备关联的标题。该框架使用可用的 用于确定用户位置和航向的硬件。你使用 此框架中的类和协议来配置和调度 地点和标题事件的交付。您还可以使用它来定义 地理区域和监视用户何时跨越 这些地区。在iOS中,您还可以定义蓝牙周围的区域 灯塔


.

只需向用户发送短信并告诉他用当前lat lngSee回复即可。请您阅读问题。再次?@iTroyd23 CLLocation在某些情况下可以在没有Internet连接的情况下返回结果。@iTroyd23在所有情况下都是什么意思。你自己试过什么。