代码之家  ›  专栏  ›  技术社区  ›  ennuikiller

iphone UpdateLocation在3G上的工作方式与无线网络不同?

  •  1
  • ennuikiller  · 技术社区  · 15 年前

    我有一个简单的mapview,它具有以下viewdidload方法和didupdate to location:

    - (void)viewDidLoad {
        NSLog(@"in view did load");
        [super viewDidLoad];
        self.mapView.showsUserLocation = YES;
        self.put_url = nil;
    
    
        locationManager = [[CLLocationManager alloc] init];
        [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
        [locationManager setDelegate:self];
    
        noUpdates = 0;
        [locationManager startUpdatingLocation];
    
        self.availableParking = [[NSMutableArray alloc] init];
        //self.availableParking = nil;
    
    }
    
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    
        NSLog(@"in didupdatetolocatoin");
         if([newLocation horizontalAccuracy] < 100 && [newLocation horizontalAccuracy] > 0) {
    
    
        // Add annotation to map
        DDAnnotation *annotation = [[DDAnnotation alloc] initWithCoordinate:newLocation.coordinate title:@"Park Here?"];
    
        MKCoordinateRegion region;
        MKCoordinateSpan   span;
        span.latitudeDelta = 0.05;
        span.longitudeDelta = 0.05;
    
    
        region.span = span;
        region.center = newLocation.coordinate;
    
    
    
        self.mapView.region = region;
    
    
    
        NSLog(@"in didupdatetolocation");
        noUpdates++;
             NSLog(@"IN UPDATELOCATION NOUPDATES = %d",noUpdates);
        if (noUpdates == 1) {
            [self.mapView addAnnotation:annotation];
            NSLog(@"ADDED ANNOTATION IN didUpdateToLocation!!");
    
    
            [locationManager stopUpdatingLocation];
            [self.settingsViewController setState:self.mapView.userLocation.subtitle andCity:@"fuckface"];
    
    
    
            NSLog(@"STOPPED UPDATING LOCATION");
    
    
            UpdateLocation *updatedLocation = [[[UpdateLocation alloc] initWithUserid:@"fuckface" andCoordinate:newLocation.coordinate withMapViewController:self]
                                               autorelease];
            NSLog(@"Lat = %f, Long = %f",newLocation.coordinate.latitude,newLocation.coordinate.longitude);
            //[NSThread detachNewThreadSelector:@selector(getLocations) toTarget:self withObject:nil];
            [[NSNotificationCenter defaultCenter]
             addObserver:self
             selector:@selector(sendUpdate)
             name:@"NoteFromOne"
             object:updatedLocation]; 
    
    
            }
        // We only update location once, and let users to do the rest of the changes by dragging annotation to place they want
    
            }  else {
                NSLog(@"Accuracy not good enough %lf", [newLocation horizontalAccuracy]);
    
            }
    
    
    
    }
    

    以下是几个屏幕截图:

    使用3G: alt text http://www.freeimagehosting.net/uploads/fe7fcbb2ea.jpg

    使用wifi: alt text http://www.freeimagehosting.net/uploads/6b653e60a7.jpg

    1 回复  |  直到 15 年前
        1
  •  0
  •   Massimo Cafaro    15 年前

    GPS装置与网络连接无关(除非GPS信号不可用,在这种情况下,GPS可能会尝试使用wifi热点或设备连接的手机来推断您的位置)。如果GPS信号可用,并且网络仅用于实际显示地图,则它独立于GPS信号工作。根据你发布的截取代码,你只能在水平精度低于100米时显示地图,否则你会让GPS装置更新位置。但是,如果您在完全相同的位置尝试代码,则设备上的GPS单元应始终返回相同的更新。因此,我真的不理解您所描述的行为:只有当GPS信号不可用时,当不同的网络连接可用时,GPS单元为同一地点返回不同的更新时,这才可能发生。你在这两种情况下看到的纬度/经度是否相同?你看到了同样的准确度吗?在这两种情况下,务必在完全相同的位置测量。

    如果您获得了相同的更新,那么可能是您的3G手机连接功能不够强大,或者只是明显可用,因此您没有获得地图。尝试在同一地点测试3G网络的速度。

    相关的考虑。您应该允许GPS装置工作,直到经过指定的时间量(例如20秒,使用NSTimer)或达到指定的精度水平,以先发生的为准。否则,您可能会消耗太多的电池。