CLLocationManager没有互联网吗?

时间:2011-09-08 10:44:56

标签: iphone ipad cllocationmanager

愚蠢的问题!!虽然我想知道CLLocationManager可以在没有Internet的情况下工作吗?????

即。 iPhone根本没有连接到互联网

4 个答案:

答案 0 :(得分:13)

iPhoneiPadDev的答案有点错误:虽然有时位置管理器会失败,但它可以在没有网络连接的情况下工作。如果你想亲眼看到这个,那么在某个可能或不存在蜂窝接收的地方开车:GPS仍然有用。

这在很大程度上取决于您周围的环境条件以及您正在使用的设备。 iPod Touches和一些iPad没有GPS,并依靠WiFi热点来确定他们的位置数据。如果您没有网络访问权限,CLLocationManager将返回无效位置。

iPhone和3G iPad 有GPS,因此您可以获得返回的适当位置。 然而,他们使用A-GPS(辅助GPS),它使用来自网络的信息以实现更快的GPS锁定。如果您没有互联网连接,那么GPS芯片可能需要一些时间才能获得信号并提供准确的位置:如果您在室内或者看不到天空,则精确度可能会大幅下降。

重点CLLocationManager可以并且即使没有可用位置也会返回您的位置:但坐标无效。重要的是要测试返回的位置,并确保在使用它们之前确定它们是正确的。

答案 1 :(得分:4)

是否可以在终端设置中启用定位服务。无需互联网连接。

答案 2 :(得分:0)

是的,但是在天空中(指道路,地面)。

  1. 如果您在线,则将通过wifi,移动数据获取位置坐标,然后,如果您关闭互联网并更改了位置(远离该位置),则说您现在在大楼(三楼),那么您就不会获取正确的位置更新,而是获取缓存坐标。

要解决此问题:

在离线模式下记录时间戳(说“ RecordDate”),当您要定位时,比较一下didUpdateToLocations:方法提供的时间戳。

如果didUpdateToLocations的时间戳>已记录的时间戳,则使用它

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(nonnull NSArray<CLLocation *> *)locations
{
    CLLocation *currentLocation = [locations lastObject];
    NSLog(@"didUpdateToLocation: %@", currentLocation);

    NSDate *eventDate=[[NSUserDefaults standardUserDefaults] objectForKey:@"RecordDate"];

    NSComparisonResult result = [currentLocation.timestamp compare:eventDate];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd HH:mm:ss z"];
    switch (result)
    {
        case NSOrderedAscending: {
            NSLog(@"Location%@ is greater than %@", [df stringFromDate:eventDate], [df stringFromDate:currentLocation.timestamp]);

        }
            break;
        case NSOrderedDescending:
            NSLog(@"%@ is less %@", [df stringFromDate:eventDate], [df stringFromDate:currentLocation.timestamp]);
            if (currentLocation != nil)
            {
                 //Use them
                //currentLocation.coordinate.latitude
                // currentLocation.coordinate.longitude
            }
            break;
        case NSOrderedSame:
            //Use them
            break;
        default:
            NSLog(@"erorr dates %@, %@", [df stringFromDate:eventDate], [df stringFromDate:currentLocation.timestamp]);
            break;
    }
}

答案 3 :(得分:0)

“核心位置”使用多种传感器来获取位置:蓝牙,Wi-Fi,GPS,气压计,磁力计以及Apple所谓的“蜂窝硬件”。 GPS,BLE,气压计和磁力计都不需要数据连接。