如何将自定义标记从服务器添加到 google 地图? Swift

How to add custom markers from server to google map? Swift

我正在开发应用程序,它可以显示用户的位置并加载附近的地点。位置是通过坐标从服务器获取的。所以我的问题是如何将它们显示为具有正确大小的自定义标记?我正在将坐标加载到一个数组,然后在地图上显示它们。这是我有多远:

滚动时标记变大。

这是我设置标记的地方:

 let coordinates = spotCoordinates
let image = UIImage(named: "Dog")!.withRenderingMode(.alwaysTemplate)
for coord in coordinates {
   let position = CLLocationCoordinate2D(latitude: coord.latitude,longitude:coord.longitude)
    let marker = GMSMarker(position: position)
    marker.map = spotsParentView.mapView
    marker.icon = image
}

您必须像这样在数组中添加标记图标和位置:

 let marker = GMSMarkerInfo()
  marker.icon = UIImage(named: "locationPinNeon")
   self.markerArray.append(marker)                

然后要在地图上从服务器获取的位置显示标记,您必须执行以下代码:

 let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: Double(self.lat)!, longitude: Double(self.long)!, zoom: 5.0)
                self.mapView.camera = camera

                delay(seconds: 1) { () -> () in
                    //fit map to markers
                    var bounds = GMSCoordinateBounds()
                    for marker in self.markerArray {
                        bounds = bounds.includingCoordinate(marker.position)
                    }
                    let update = GMSCameraUpdate.fit(bounds, withPadding: 100.0)
                    self.mapView.animate(with: update)
                }