【发布时间】:2023-03-07 04:11:01
【问题描述】:
在我的应用程序中,我需要向用户展示他在 GMSMapView 中移动的方向,所以我已经放置了自定义 GMSMarker 并设置了图像(例如。 Bike or Car) 并在用户开始移动时为该标记设置动画并在 locationManager didUpdateHeading 委托方法中更改标记的角度,因为 GMSMarker 图像(Bike 或 Car)应该开始朝向用户移动方向。
下面是正在使用的代码,但是当用户缓慢移动说走路时它可以正常工作,而当用户快速移动说在 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];
}
谁能告诉我现在应该怎么做才能在用户快速移动时显示正确的准确标题。
【问题讨论】:
-
您可能有使用课程选项。请参考此developer.apple.com/library/content/documentation/…,尤其是在快速移动时 v 似乎需要使用课程
标签: ios iphone cllocationmanager gmsmapview