在iOS中获取用户当前旋转角度的谷歌地图

时间:2018-06-14 11:15:16

标签: ios iphone google-maps google-maps-sdk-ios

我在应用程序中使用谷歌地图。当我不旋转地图时一切正常。但是当我旋转地图时,我遇到问题,如图所示。为了解决这个问题,我需要让用户获得当前旋转角度的谷歌地图。我需要这样才能将标记以相同的角度放回地图上。目前我的地图角度在旋转之后和我的叠加层在将计划图像放置在地图上之后似乎是不同的,即使我正确得到左上角和右上角。右下角坐标。 我的代码

let topCoordinate = CLLocationCoordinate2D(latitude: topLattitude, longitude: topLongitude)//top
let bottomCoordinate = CLLocationCoordinate2D(latitude: bottomLattitude, longitude: bottomLongitude)//bottom
overlayBounds = GMSCoordinateBounds(coordinate: topCoordinate, coordinate:
bottomCoordinate)

let overlay = GMSGroundOverlay(bounds: overlayBounds, icon: planImage)
    overlay.map = mapView

Image showing map is rotated & overlay is in default angle & they both are different in in this case. If I do not rotate map everything works fine.

2 个答案:

答案 0 :(得分:0)

func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
print(position.bearing)

相机的轴承,从正北方向顺时针旋转。

WITH
t AS
(
    SELECT
        COL1
    FROM
        TABLE1
)
SELECT
 *
FROM
TABLE2
WHERE
COL2 IN ( SELECT COL FROM t )

}

答案 1 :(得分:0)

我通过将overlay方法更改为

解决了我的问题
let zoomLevel = (object["image_zoom_level"] as? NSString)?.doubleValue
let overlay = GMSGroundOverlay(position: centreCoordinate, icon: planImage, zoomLevel: CGFloat(zoomLevel!))
overlay.map = mapView
if let angle = (object["rotation_angle"] as? NSString)?.doubleValue{
     overlay.bearing = angle
}

我没有使用覆盖范围,而是使用了中心坐标,并使用图像缩放级别和旋转角度放置了覆盖图像。这样,我的图像就以适当的角度和适当的位置放置了。如果图像尺寸正确无误,并且中心点准确准确,则此方法效果很好。