我有一个简单的mapview,它有以下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: alt text http://www.freeimagehosting.net/uploads/fe7fcbb2ea.jpg
使用wifi: alt text http://www.freeimagehosting.net/uploads/6b653e60a7.jpg
答案 0 :(得分:0)
GPS单元与网络连接无关(除非GPS信号不可用,在这种情况下GPS可能会尝试使用wifi热点或设备所连接的单元以推断您的位置) 。如果GPS信号可用,它可以独立工作,并且网络仅用于实际显示地图。从您发布的剪辑代码中,只有当您达到小于100米的水平精度时才显示地图,否则您将让GPS单元更新位置。但是,如果您在完全相同的位置尝试代码,设备上的GPS设备应始终返回相同的更新。因此,我真的不明白你所描述的行为:只有当GPS信号不可用时,当不同的网络连接可用时,GPS单元才会返回同一地点的不同更新。您是否在两种情况下看到相同的纬度/经度?你看到同样的准确度吗?在两种情况下,请小心地在完全相同的位置进行测量。
如果您获得相同的更新,那么您的3G蜂窝连接可能不够强大或者只是显而易见,因此您无法获得地图。尝试从同一个地方测试3G网络的速度。
相关的考虑因素。您应该允许GPS装置工作,直到经过指定的时间(例如20秒,使用NSTimer)或直到达到指定的准确度,以先发生者为准。否则你最终可能会消耗太多电池。