在我的应用程序中显示与谷歌地图相同的侧视图

时间:2015-09-21 10:56:42

标签: ios objective-c google-maps

我正在开发一个基于导航的应用程序,其中我使用谷歌地图和谷歌方向api进行路线导航,但我卡在一点,我需要显示相同的谷歌地图侧面视图,当我们开始导航时打开。

我有R& D批次,但不能完全像谷歌地图侧视图那样。

我尝试使用以下

 GMSCameraPosition *camera =[GMSCameraPosition cameraWithTarget:marker.position zoom:50.0 bearing:120 viewingAngle:90];
[[self getMapView] animateToCameraPosition:camera];  

无法显示相同内容。

当我开始导航时,我需要显示相同的谷歌地图。在这一点上任何人都可以帮助我。谢谢提前

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以在2个位置之间使用适当的轴承。 (现在和目标地点)

func degreesToRadians(degrees: Double) -> Double { return degrees * .pi / 180.0 }
    func radiansToDegrees(radians: Double) -> Double { return radians * 180.0 / .pi }

    func getBearingBetweenTwoPoints1(point1 : CLLocation, point2 : CLLocation) -> Double {

        let lat1 = degreesToRadians(degrees: point1.coordinate.latitude)
        let lon1 = degreesToRadians(degrees: point1.coordinate.longitude)

        let lat2 = degreesToRadians(degrees: point2.coordinate.latitude)
        let lon2 = degreesToRadians(degrees: point2.coordinate.longitude)

        let dLon = lon2 - lon1

        let y = sin(dLon) * cos(lat2)
        let x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon)
        let radiansBearing = atan2(y, x)

        return radiansToDegrees(radians: radiansBearing)
    }



let bearingPoint = self.getBearingBetweenTwoPoints1(point1: location!, point2: self.featureLocation)
let camera = GMSCameraPosition.camera(withLatitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!, zoom: 50, bearing: bearingPoint, viewingAngle: 45)

self.mapView?.animate(to: camera)