我希望 google 地图标记保持在地图的中心,而相机位置可以改变 iOS SDK

I want google maps marker to stay in the centre of the map while camera position can change iOS SDK

我正在开发一个使用 google 地图的 iOS 应用程序。我希望标记在拖动地图或更改相机位置时粘在屏幕中央。我已经实现了下面的代码。它使标记保持在屏幕的中心,但是当我们将地图和重新定位到中心时,标记会移动。我想让它保持在屏幕中央而不移动它。

- (void)mapView:(GMSMapView *)pMapView didChangeCameraPosition:(GMSCameraPosition *)position {

    /* move draggable pin */
    if (movingMarker) {
        CLLocationCoordinate2D location = pMapView.camera.target;
        [movingMarker setPosition:location];
        return;
    }
}

提前致谢!

解决方法很简单!只需将图像视图放在地图视图之上,使图像视图大小相同(放置相同的约束或自动调整大小),然后将您的图钉图像设置为图像视图,将 .center contentMode 设置为图像视图。而已!您不必向地图视图本身添加标记。如果您想获得图钉(地图视图中心)坐标,请使用 mapView.projection.coordinate(for: CGPoint) of google 地图,您必须在其中传递地图视图的中心点。祝你好运!