【发布时间】:2013-05-12 07:01:48
【问题描述】:
应用程序的地图屏幕显示用户的当前位置。我想让用户“浏览”地图(滚动并探索其他区域),我有一个按钮,可以让用户返回地图上的当前位置 但是 我是发生的情况是该应用程序不允许用户“浏览”地图并保留他们正在查看的视图,而是直接跳回用户的当前位置。
这里有一些代码:
-(void) setupLocation {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
// locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// [self.mapView setCenterCoordinate:self.mapView.userLocation.coordinate animated:YES];
tempLat = newLocation.coordinate.latitude;
tempLon = newLocation.coordinate.longitude;
CLLocationCoordinate2D currentLocation = CLLocationCoordinate2DMake(tempLat, tempLon);
MKCoordinateRegion viewRegionLocation = MKCoordinateRegionMakeWithDistance(currentLocation, 100, 100);
[self.mapView setRegion:viewRegionLocation animated:YES];
locationNew = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
locationOld = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];
}
我也有:
- (IBAction)stopUpdating:(id)sender {
[locationManager stopUpdatingLocation];
}
还有:
- (IBAction)findMe:(id)sender {
[locationManager startUpdatingLocation];
}
任何关于为什么地图不断跳回用户当前位置的想法?
非常感谢!
【问题讨论】:
标签: ios mapkit core-location