ios - 在 GMSMapView 上显示折线的开始和结束标记
问题描述
iOS 中的 GSMapView 具有不同的功能来覆盖谷歌地图上的折线。有没有办法在折线的起点和终点显示标记?折线的点只是字符串。
// MARK: - Polyline
struct Polyline: Codable {
let points: String?
}
是否可以提取第一个和最后一个点并将它们添加为谷歌地图上的标记?
解决方案
您如何定义折线的路径?
您可以将折线的路径定义为GMSMutablePath()
可以添加坐标值以定义折线的起点和终点的位置。
例如,您可以定义一条从 Melborne 到 Perth 的折线:
let path = GMSMutablePath()
path.addLatitude(-37.81319, longitude: 144.96298)
path.addLatitude(-31.95285, longitude: 115.85734)
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 5.0
polyline.geodesic = true
polyline.map = mapView
然后,您可以使用这些坐标在折线的起点和终点添加一个标记:
let melbourneMarker = GMSMarker();
melbourneMarker.position = CLLocationCoordinate2D(latitude: -37.81319, longitude: 144.96298)
melbourneMarker.map = mapView;
let perthMarker = GMSMarker();
perthMarker.position = CLLocationCoordinate2D(latitude: -31.95285, longitude: 115.85734)
perthMarker.map = mapView;
供您参考,您可以查看此折线文档。结果,它看起来像这样:
推荐阅读
- c# - 在较大的图像中查找形状不规则的图像
- javascript - 我在 graphql/graphql-js repo 中找到了一个 `Object.prototype.inspect` 代码片段,在什么情况下会调用它?
- php - 根据共同值制作数组
- r - 在模拟线性回归中,为什么标准差与变量的平方根成正比?
- elasticsearch - 流利的完整缓冲区无法将日志发送到弹性搜索
- c# - 如何在 C# 中删除 windows-10 安全选项卡中的异常隐藏字符
- python - 如何使用外部 USB 相机数据正确格式化 PIL.Image.frombytes
- nginx - 无法访问花
- flutter - 用于颤振的 Agora.io 通道加密不适用于跨平台
- python - 使用 Python3 启动带有参数的 Docker 容器