我已经实现了- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {方法来更改userLocation注释的默认位置。在这个方法中,我使用了:
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注释在下面。那怎么做呢?
更新
我发现了this的问题,并试着应用它。但是由于我使用的标题,所以它崩溃了应用程序。在我的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];,因为我使用的是标题,因此动画设置为NO。但是现在,当我运行代码时,它开始在中间点和新点之间旋转。
发布于 2016-07-20 13:07:27
MKCoordinateRegion区域= mapClinicsView.region;
设置“region.center”将帮助您导航地图中心位置
确保“region.center”和批注中心纬度和经度相同
https://stackoverflow.com/questions/38481559
复制相似问题