viewForAnnotation没有移动userLocation
我已经实现了- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
方法来更改userLocation Annotation的默认位置。 在这个方法里面我使用了:
if (annotation==(mapView.userLocation)) { MKAnnotationView *myAnotation = [[MKAnnotationView alloc] init]; myAnotation.image = self.userPointImage.image; myAnotation.centerOffset = CGPointMake(0, 250); return myAnotation; } else { return nil; }
其中成功将默认userLocation注释移动到中心底部。 但是,因为我也在使用标题,所以当移动我的手机时,它仍然从中心旋转地图。
- (void)locationManager:(CLLocationManager *) manager didUpdateHeading:(CLHeading *) newHeading { [self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:true]; }
但userLocation注释如下。 那么该怎么做?
UPDATE
我发现这个问题,并尝试应用它。 但是,因为我正在使用标题,所以它崩溃的应用程序。 在我的didUpdateUserLocation
方法中,我添加了[self moveCenterByOffset:CGPointMake(0, 200) from:userLocation.coordinate];
而这个方法如下:
- (CLLocationCoordinate2D)moveCenterByOffset:(CGPoint)offset from:(CLLocationCoordinate2D)coordinate { CGPoint point = [self.mapView convertCoordinate:coordinate toPointToView:self.mapView]; point.x += offset.x; point.y += offset.y; CLLocationCoordinate2D center = [self.mapView convertPoint:point toCoordinateFromView:self.mapView]; return center; }
然后在我didUpdateUserLocation
方法更新它: MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([self moveCenterByOffset:CGPointMake(0, -250) from:userLocation.coordinate], 800.0f, 200.0f);
和[mapView setRegion:region animated:NO];
因为我正在使用标题,所以animation设置为NO
。 但是现在,当我运行代码时,它开始在中心点和新点之间跳动。
MKCoordinateRegion region = mapClinicsView.region;
设置“region.center”这将有助于您浏览您的地图中心位置
确保“region.center”和注释中心的结合和结合是一样的