首页 > 解决方案 > 当缩小标记在Swift 4中改变位置时

问题描述

我也尝试过地面覆盖,但它不起作用

我没有找到任何解决方案请帮忙。有人知道这个的解决方案吗?

for state in self.asset {

    let state_marker = GMSMarker()

    self.appTitle = state.appName    
    if state.appName == "AssetHistory"{
        path.add(CLLocationCoordinate2D(latitude: CLLocationDegrees(state.Latitude), longitude: CLLocationDegrees(state.Longitude)))
        bounds = GMSCoordinateBounds(path: path)
        if self.asset.first?.Latitude as CGFloat! == state.Latitude && self.asset.first?.Longitude as CGFloat! == state.Longitude
        {
            state_marker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees(state.Latitude), longitude: CLLocationDegrees(state.Longitude))
            state_marker.icon = UIImage(named: "arrow_blue")
            state_marker.title = "Start"
            bounds = bounds.includingCoordinate(state_marker.position)
        }
        if self.asset.last?.Latitude as CGFloat! == state.Latitude && self.asset.last?.Longitude as CGFloat! == state.Longitude
        {
            state_marker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees(state.Latitude), longitude: CLLocationDegrees(state.Longitude))            
            state_marker.icon = UIImage(named: "arrow_red")
            state_marker.title = "End"
            bounds = bounds.includingCoordinate(state_marker.position)
        }
    }else{
        path.removeAllCoordinates()
        state_marker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees(state.Latitude), longitude: CLLocationDegrees(state.Longitude))
        let im = UIImage(named: state.Direction)
        state_marker.icon = self.imageWithImage(image: im!, scaledToSize: CGSize(width: 100.0, height: 100.0))
        state_marker.title = "\(state.AssetName)"
        bounds = bounds.includingCoordinate(state_marker.position)
    }
    state_marker.infoWindowAnchor = CGPoint(x: 0.5, y: 0.5)
    state_marker.tracksViewChanges = true
    state_marker.map = self.mapView
    state_marker.userData = state_marker.title    
}

标记不在位

标签: swiftgoogle-maps

解决方案


问题来自您的标记groundAnchor,地图正在正确绘制标记,但您应该根据其图像设置每个标记groundAnchor。

地面锚点指定图标图像中锚定到地球表面上标记位置的点。该点在连续空间 [0.0, 1.0] x [0.0, 1.0] 内指定,其中 (0,0) 是图像的左上角,(1,1) 是右下角。如果图像有非零的alignmentRectInsets,上面提到的左上角和右下角是指图像的inset部分。


推荐阅读