【问题标题】:How to get the user location With out internet connectivity [duplicate]如何在没有互联网连接的情况下获取用户位置[重复]
【发布时间】:2014-05-19 12:00:19
【问题描述】:

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

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

【问题讨论】:

标签: ios iphone objective-c gps


【解决方案1】:

在你的@implementation 中添加这些变量:

CLLocationManager *manager;
CLGeocoder *geocoder;

在你看来DidLoad:

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。

【讨论】:

  • 请您阅读问题。再来一次?
  • @iTroyd23 CLLocation 在某些情况下可以在没有 Internet 连接的情况下返回结果。
  • @iTroyd23 你是什么意思所有情况。你自己试过什么。
【解决方案2】:

看看corelocation

核心位置框架可让您确定当前位置或 与设备关联的标题。该框架使用可用的 硬件来确定用户的位置和航向。您使用 这个框架中的类和协议来配置和调度 传递位置和航向事件。你也可以用它来定义 地理区域并监控用户何时跨越边界 那些地区。在 iOS 中,您还可以在蓝牙周围定义一个区域 信标

.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 2017-09-09
    • 2013-02-17
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    相关资源
    最近更新 更多