gpt4 book ai didi

ios - 沿用户面向的方向旋转 GMSMarker

转载 作者:IT王子 更新时间:2023-10-29 08:19:43 30 4
gpt4 key购买 nike

我有一个要求,比如在我当前的位置将显示一个 View 。如果设备旋转或位置将发生变化,它将旋转。我研究了很多但得到了所有在某个位置具有固定位置或角度但我没有固定位置的代码。任何人都可以在正确的方向引导我。

我还使用了 GMSMarker 的 rotation 属性,但它不起作用。

- (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,因为没有转换方法。

How uber rotate their car in google map?

enter image description here

最佳答案

我们可以根据类(class)属性 CLLocation Class 旋转图像

    let marker = GMSMarker(position: currentLocation!)
let head = locationManager.location?.course ?? 0
marker.rotation = head
marker.icon = UIImage(named: "testyCar.png")
marker.map = mapView

关于ios - 沿用户面向的方向旋转 GMSMarker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36450526/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com