2014-05-19 30 views
-1

我需要获取用户的经度和纬度,即使互联网设施在iOS中不可用。如何获取用户位置无需互联网连接

注意:没有互联网,没有蜂窝网络和蜂窝服务。

+0

只需发送用户短信,并告诉他回复当前的经纬度 –

+1

请参阅:http://stackoverflow.com/questions/14326890/is-it-possible-to-use-core-location-gps-没有任何互联网连接disa – Ricky

回答

0

在你的@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在你的框架中。

+0

你可以请阅读问题。再次? –

+0

@ iTroyd23在某些情况下,CLLocation可以返回没有Internet连接的结果。我需要在所有情况下都需要 –

+0

。 –

0

看一看corelocation

的Core Location框架可以让你确定当前位置或 航向与设备相关联。该框架使用可用的硬件来确定用户的位置和标题。您可以在此框架中使用 类和协议来配置和安排位置和标题事件的传递。您还可以使用它来定义 地理区域,并监视用户何时穿越这些区域的边界。在iOS中,您还可以定义围绕蓝牙的区域信标