我有一个简单的地图视图,它具有以下 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