swift - 当缩小标记在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
}
解决方案
问题来自您的标记groundAnchor,地图正在正确绘制标记,但您应该根据其图像设置每个标记groundAnchor。
地面锚点指定图标图像中锚定到地球表面上标记位置的点。该点在连续空间 [0.0, 1.0] x [0.0, 1.0] 内指定,其中 (0,0) 是图像的左上角,(1,1) 是右下角。如果图像有非零的alignmentRectInsets,上面提到的左上角和右下角是指图像的inset部分。
推荐阅读
- dart - 在 Flutter 中使用完整的 Dart SDK
- angular - 访问 Nativescript angular 组件中的 exoplayer 元素
- sql - sql查找列的最大值并选择为新字段
- apache-spark - 连接到 HiverServer2 后的 Spark 读取表只提供模式而不是数据
- security - 带有设备内存的幽灵
- git - 将 git 推送到服务器:说“致命:不是 git 存储库”
- dart - const 在 Flutter 中定义 EdgeInsets 中的作用
- c++ - 空 unordered_map 上的 find() 会导致访问冲突吗?
- java - opencsv 从未知行但已知单词读取?
- javascript - 使用 Axios 从 http 响应下载 PDF