我可以使用Google地图中的位置旋转汽车吗?

时间:2018-09-26 12:55:49

标签: ios swift google-maps

我从套接字获得了此数据,我需要更改 车基于更改的位置。我该如何旋转(左,右,上, 底部)的车?

{
    carType = Sedan;
    latitude = "41.738751";
    longitude = "-88.274285";
}

我也尝试这样做,但是不起作用:

float dy = newLocation.latitude - oldLocation.latitude;
float dx = cosf(M_PI/180*oldLocation.latitude)*(newLocation.longitude - oldLocation.longitude);
float angle = atan2f(dy, dx);
driverMarker.rotation = angle;

enter image description here

3 个答案:

答案 0 :(得分:0)

您可以更改轮播方式,例如:

marker.rotation = angle value

答案 1 :(得分:0)

您可以使用它来获得旋转汽车标记的角度:

func angleBetween(oldLocation: CLLocation, newLocation: CLLocation) -> Double {
    let originLocation = CLLocation(latitude: newLocation.coordinate.latitude - oldLocation.coordinate.latitude, longitude: newLocation.coordinate.longitude - oldLocation.coordinate.longitude)
    let bearingRadians = atan2(originLocation.coordinate.latitude, originLocation.coordinate.longitude)
    let bearingDegrees = bearingRadians * 180 / Double.pi
    return bearingDegrees 
}

您可以像这样使用它

let angle = angleBetween(oldLocation: oldLocation, newLocation: newLocation)

您可以像@Daljeet所说的那样使用marker.rotation

marker.rotation = angle

答案 2 :(得分:0)

使用核心位置委托方法。 它将给出您手机的方向。

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) 
{

        let direction = newHeading.trueHeading as Double
        print("Direction :- \(direction)");
        currentLoaction.rotation = direction
}

设置位置标记的方向。 此处: currentLoaction

var currentLoaction:GMSMarker = GMSMarker()

希望这对您使用Google Map会有所帮助。