【问题标题】:Show starting and ending marker of Polyline on GMSMapView在 GMSMapView 上显示折线的开始和结束标记
【发布时间】:2020-12-30 20:07:18
【问题描述】:

iOS 中的 GSMapView 具有不同的功能来覆盖谷歌地图上的折线。有没有办法在折线的起点和终点显示标记?折线的点只是字符串。

// MARK: - Polyline
struct Polyline: Codable {
    let points: String?
}

是否可以提取第一个和最后一个点并将它们作为标记添加到谷歌地图上?

【问题讨论】:

    标签: ios swift google-maps google-maps-markers google-polyline


    【解决方案1】:

    您如何定义折线的路径?

    您可以将折线的路径定义为GMSMutablePath(),您可以在其中添加坐标值来定义折线的起点和终点。

    例如,您可以定义一条从梅尔伯恩到珀斯的折线:

    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;
    

    供您参考,您可以查看此polyline documentation。因此,它看起来像这样:

    【讨论】:

    • 假设,我只有折线,没有别的。使用折线,我们可以在谷歌地图上绘制。但是从折线本身,我想提取起点和终点。
    • 我可以知道你在哪里得到折线吗?该特定折线的路径是如何定义的?
    • 其他团队创建了一个框架,为我正在处理的模块提供折线细节。
    猜你喜欢
    • 2014-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 2014-12-30
    相关资源
    最近更新 更多