在我的应用程序中,我需要在GMSMapView中显示用户沿着他移动的方向移动,所以我已经放置了自定义GMSMarker并设置了图像(例如自行车或汽车)并在用户开始移动和更改角度时为该标记设置动画locationManager didUpdateHeading委托方法中的标记,因为 GMSMarker 图像(自行车或汽车)应该开始朝向用户移动方向。
下面是正在使用的代码,但是当用户缓慢移动时它可以正常工作说走路,而当用户快速移动说在 40+ 速度的自行车或汽车时不能正常工作。
- (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];
}
谁能告诉我当用户快速移动时我现在应该做什么来显示正确的准确标题。