Ios 如何旋转GMSMarker以显示用户移动方向?
在我的应用程序中,我需要在一个GMSMapView中显示用户沿着他移动的方向移动,因此我已经设置了自定义GMSMarker并设置了图像(例如自行车或汽车)并在用户开始移动时设置该标记的动画,并在locationManager didUpdateHeading委托方法中更改标记的角度,因为GMSMarker图像(自行车或汽车)应开始朝向用户移动方向 下面是我正在使用的代码,但是当用户移动缓慢时它会工作,比如说走路,当用户快速移动时它会工作不正常,比如在自行车或汽车中以40+的速度移动Ios 如何旋转GMSMarker以显示用户移动方向?,ios,iphone,cllocationmanager,gmsmapview,Ios,Iphone,Cllocationmanager,Gmsmapview,在我的应用程序中,我需要在一个GMSMapView中显示用户沿着他移动的方向移动,因此我已经设置了自定义GMSMarker并设置了图像(例如自行车或汽车)并在用户开始移动时设置该标记的动画,并在locationManager didUpdateHeading委托方法中更改标记的角度,因为GMSMarker图像(自行车或汽车)应开始朝向用户移动方向 下面是我正在使用的代码,但是当用户移动缓慢时它会工作,比如说走路,当用户快速移动时它会工作不正常,比如在自行车或汽车中以40+的速度移动 - (voi
- (void)viewDidLoad {
[super viewDidLoad];
if(locationManager == nil) {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = 10.0;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
[locationManager requestAlwaysAuthorization];
if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
// Start heading updates.
if ([CLLocationManager headingAvailable]) {
locationManager.headingFilter = 5;
[locationManager startUpdatingHeading];
}
}
}
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
// Use the true heading if it is valid.
CLLocationDirection direction = newHeading.magneticHeading;
CGFloat radians = -direction / 180.0 * M_PI;
//For Rotate Niddle
CGFloat angle = RADIANS_TO_DEGREES(radians);
[self rotateArrowView:angle];
}
-(void)rotateArrowView:(CGFloat)degrees {
currentLocationMarker.rotation = degrees;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
// If it's a relatively recent event, turn off updates to save power.
currentLocation = [locations lastObject];
[CATransaction begin];
[CATransaction setAnimationDuration:0.5];
currentLocationMarker.position = currentLocation.coordinate;
[CATransaction commit];
}
有谁能告诉我,当用户快速移动时,我现在应该做什么来显示正确的准确航向。嗯,我不是很确定,但在快速驾驶时,航向似乎不是很准确。我看到几个选择:
您可能有“使用课程”选项。请参考这一点,特别是当快速移动v需要使用课程时