我正在尝试获取用户位置,并使用iOS6中的以下代码将其显示在mapView中
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
if (locations.count>0) {
for (CLLocation *location in locations) {
[locationList addObject:location];
if (location != nil) {
// Zoom to the current user location.
MKCoordinateRegion userLocation =[mapView regionThatFits: MKCoordinateRegionMakeWithDistance(location.coordinate, 150.0, 150.0)];
[mapView setRegion:userLocation animated:YES];
NSLog(@"%f,%f", mapView.centerCoordinate.latitude,mapView.centerCoordinate.longitude);
NSLog(@"%f,%f", mapView.region.span.latitudeDelta,mapView.region.span.longitudeDelta);
}
}
}}
但在位置更新后,[mapView setRegion:userLocation animated:YES]不会对mapView的区域进行任何更改,但用户位置可以显示为一个蓝点。NSLog打印如下:
nan,nan
0.000000,360.000000也就是说什么都没变。我检查了大多数与地图相关的问题,他们只是调用这个方法,并在地图的中心显示位置。
我想知道为什么我可以把用户位置放到地图中心。
发布于 2013-01-18 03:43:11
您只需打开MKMapView跟踪模式
[mapView setTrackingMode:MKMapViewTrackingModeFollowsUser];发布于 2013-06-06 11:09:49
您可以尝试这样做:
mMapView.showsUserLocation = YES;https://stackoverflow.com/questions/14373243
复制相似问题