1

我有一个简单的地图视图,它具有以下 viewdidload 方法并确实更新到位置:

- (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 网络上,它永远不会缩放或丢弃图钉。关于为什么的任何想法?提前致谢。

这是几个屏幕截图:

使用 3G: 替代文字 http://www.freeimagehosting.net/uploads/fe7fcbb2ea.jpg

使用 wifi: 替代文字 http://www.freeimagehosting.net/uploads/6b653e60a7.jpg

4

1 回答 1

0

GPS 单元与网络连接无关(除非 GPS 信号不可用,在这种情况下,GPS 可能会尝试使用 wifi 热点或您的设备连接的小区来推断您的位置)。如果 GPS 信号可用,则它独立于它工作,并且网络仅用于实际显示地图。从您发布的代码中,您仅在水平精度小于 100 米时才显示地图,否则您会让 GPS 单元更新位置。但是,如果您在完全相同的位置尝试您的代码,则设备上的 GPS 单元应始终返回相同的更新。因此,我真的不明白你所描述的行为:仅当 GPS 单元在不同的网络连接可用时为同一地点返回不同的更新时,这是可能的,因为 GPS 信号不可用。在这两种情况下,您是否看到相同的纬度/经度?您是否看到相同的准确性?在这两种情况下,请注意在完全相同的位置进行测量。

如果您获得相同的更新,那么您的 3G 蜂窝连接可能根本不够强大或只是表面上可用,因此您没有获得地图。尝试从同一个地方测试您的 3G 网络的速度。

一个相关的考虑。您应该让 GPS 单元工作直到经过指定的时间量(比如 20 秒,为此使用 NSTimer)或直到您达到指定的准确度级别,以先发生者为准。否则,您最终可能会消耗过多的电池。

于 2009-10-18T11:01:51.990 回答