在面向用户的方向上旋转GMSMarker [英] Rotate GMSMarker in direction at which user facing
问题描述
我要求在当前位置显示一个视图。如果设备旋转或位置将改变它将旋转。我研究很多,但得到了在某个位置有固定位置或角度的所有代码,但我没有修复位置。任何人都可以向我推进正确的方向。
I have requirement like on my current location one view will display. It will rotate if device was rotate or location will be change.I research lot but got all the code which have a fix location or angle at some location but i haven't fix location. Can anyone drive me at right direction.
我还使用了GMSMarker的旋转属性,但它无效。
I also used rotation property of the GMSMarker but it is not working.
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
if (newHeading.headingAccuracy < 0){
NSLog(@"heading accuracy < 0");
return;
}
// Convert Degree to Radian and move the needle
float oldRad = (- manager.heading.trueHeading) * M_PI / 180.0f;
float newRad = (- newHeading.trueHeading) * M_PI / 180.0f;
// Compass animation
CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
theAnimation.fromValue = [NSNumber numberWithFloat:oldRad];
theAnimation.toValue = [NSNumber numberWithFloat:newRad];
theAnimation.duration = 0.5f;
[source.layer addAnimation:theAnimation forKey:@"animateMyRotation"];
// source.transform = CGAffineTransformMakeRotation(newRad)
// GMSMarker *source = [googleMap selectedMarker];
// source.rotation = newRad;
}
更新:我有旋转方法但是有任何旋转GMSMarker的方法都是因为没有变换方法。
Update: I have rotation method but is there any way to rotate the GMSMarker because there is no method for transform.
如何在google地图中旋转他们的汽车?
How uber rotate their car in google map?
推荐答案
我们可以根据课程属性旋转图像CLLocation Class
We can rotate image based on course property CLLocation Class
let marker:GMSMarker = GMSMarker.init(position: currentLocation!)
let head = locationManager.location?.course ?? 0
marker.rotation = head
marker.icon = UIImage(named: "testyCar.png")
marker.map = mapView
这篇关于在面向用户的方向上旋转GMSMarker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!