viewForAnnotation没有移动userLocation [英] viewForAnnotation didn't moves the userLocation

查看:130
本文介绍了viewForAnnotation没有移动userLocation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've implemented - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { method to change the default location of userLocation Annotation. Inside this method I've used:

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注释移至底部中央.但是由于我也在使用标题,因此在移动手机时,它仍会从中心旋转地图.

Which successfully moves the default userLocation annotation to center bottom. But as I'm also using heading so when move my phone it is still rotating the map from center.

- (void)locationManager:(CLLocationManager *) manager didUpdateHeading:(CLHeading *) newHeading {

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

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

更新

我发现

But the userLocation annotation is below. So how to do that?

UPDATE

I found this question and tried applying it. But as I'm using heading so it crashes the app. In my didUpdateUserLocation method I added [self moveCenterByOffset:CGPointMake(0, 200) from:userLocation.coordinate]; and this method is as follows:

- (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.但是现在,当我运行代码时,它开始在中心和新点之间抽动.

and then in my didUpdateUserLocation method I updated it as: MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([self moveCenterByOffset:CGPointMake(0, -250) from:userLocation.coordinate], 800.0f, 200.0f); and [mapView setRegion:region animated:NO]; as I'm using heading so animation is set to NO. But now as I run the code it starts jerking between center and the new point.

推荐答案

MKCoordinateRegion region = mapClinicsView.region;

MKCoordinateRegion region = mapClinicsView.region;

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

set 'region.center' It will helps you to navigate your map center position

确保'region.center'和注释中心的经纬度和经度相同

make sure 'region.center' and annotation center latitute and longitute is same

这篇关于viewForAnnotation没有移动userLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆