首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >viewForAnnotation没有移动userLocation

viewForAnnotation没有移动userLocation
EN

Stack Overflow用户
提问于 2016-07-20 12:38:54
回答 1查看 83关注 0票数 0

我已经实现了- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {方法来更改userLocation注释的默认位置。在这个方法中,我使用了:

代码语言:javascript
复制
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注释移动到中间底部。但是,由于我也使用标题,所以当移动我的手机时,它仍然从中心旋转地图。

代码语言:javascript
复制
- (void)locationManager:(CLLocationManager *) manager didUpdateHeading:(CLHeading *) newHeading {

    [self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:true];
}

但是userLocation注释在下面。那怎么做呢?

更新

我发现了this的问题,并试着应用它。但是由于我使用的标题,所以它崩溃了应用程序。在我的didUpdateUserLocation方法中,我添加了[self moveCenterByOffset:CGPointMake(0, 200) from:userLocation.coordinate];,该方法如下所示:

代码语言:javascript
复制
- (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。但是现在,当我运行代码时,它开始在中间点和新点之间旋转。

EN

回答 1

Stack Overflow用户

发布于 2016-07-20 13:07:27

MKCoordinateRegion区域= mapClinicsView.region;

设置“region.center”将帮助您导航地图中心位置

确保“region.center”和批注中心纬度和经度相同

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38481559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档