gpt4 book ai didi

ios - Gmsmap 快速旋转 View

转载 作者:行者123 更新时间:2023-11-30 11:06:57 25 4
gpt4 key购买 nike

在这张图片中GMSMapView有两个标记

  1. Green marker is pickup location and
  2. Red marker is drop location marker

我想根据拾取位置旋转ma​​pView,拾取位置希望从mapView的左侧开始,放置位置希望放置在mapView的右侧

旋转:GMSMapView 使用委托(delegate)方法或任何自定义方法

/image/Re5Mp.png

最佳答案

你可以这样尝试

extension FloatingPoint {
var degreesToRadians: Self { return self * .pi / 180 }
var radiansToDegrees: Self { return self * 180 / .pi }
}

在 View Controller 中

func getHeadingForDirection(fromCoordinate fromLoc: CLLocationCoordinate2D, toCoordinate toLoc: CLLocationCoordinate2D) -> Float {

let fLat: Float = Float((self.mapView.camera.target.latitude).degreesToRadians)
let fLng: Float = Float((self.mapView.camera.target.longitude).degreesToRadians)
let tLat: Float = Float((fromLoc.latitude).degreesToRadians)
let tLng: Float = Float((fromLoc.longitude).degreesToRadians)
let degree: Float = (atan2(sin(tLng - fLng) * cos(tLat), cos(fLat) * sin(tLat) - sin(fLat) * cos(tLat) * cos(tLng - fLng))).radiansToDegrees
if degree >= 0 {
return degree
} else {
return 360 + degree
}
}

在mapView(_mapView:GMSMapView,idleAt位置:GMSCameraPosition)

self.mapView.animate(toBearing: CLLocationDirection((self.getHeadingForDirection(fromCoordinate: self.pickUpMarker.position, toCoordinate: self.dropOffMarker.position) + 100) ))

关于ios - Gmsmap 快速旋转 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52620339/

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