ios - 在 GSMapView 中添加标记

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

我正在我的 iOS 应用程序中使用 Google map 。它将在两个坐标之间绘制线条,并在 map 上添加开始和结束位置作为“标记”。

Have a look at the image

我使用下面的代码添加开始和结束标记

    //myLatLngArrayList is array of coordinates with latitude and longitude positions
    markerA.position =  (curDrill.myLatLngArrayList.first)! as CLLocationCoordinate2D
    markerA.map = mapView
    markerA.icon = UIImage(named: markerImages.0)

    markerB.position =  (curDrill.myLatLngArrayList.last)! as CLLocationCoordinate2D
    markerB.map = mapView
    markerB.icon = UIImage(named: markerImages.1)

我使用下面的代码来绘制线条:

    let path = GMSMutablePath()
    for coord in curDrill.myLatLngArrayList {
        path.add(coord)
    }

    let drillPath = GMSPolyline.init(path: path)
    drillPath.strokeWidth = 2.0
    drillPath.strokeColor = UIColor(Utility.getDrillColor(type: curDrill.type))
    drillPath.map = mapView

问题是标记位置与线的起点和终点不匹配。标记 A 未接触行首,标记 B 未接触行尾。

我无法确定我的代码中缺少什么。

最佳答案

尝试添加您从 google API 收到的从第一个点到最后一个点的所有步数坐标。

关于ios - 在 GSMapView 中添加标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44587345/

相关文章:

android - 如何在安卓谷歌地图上开发天气应用?

ios - 具有多个路径的UIBezierPath不连接具有斜角类型的线

ios - 无法使用类型为 'contains' 的参数列表调用 '([Foo], Foo)'

google-maps - Google Places API 详细信息语言不起作用

ios - 如何将 NSArray 转换为特定的字符串?

SwiftUI Zstack – 使元素忽略安全区域而另一个不

ruby-on-rails - 从 rails-geocoder gem 中的 Controller 获取纬度和经度值

ios - 从 post 请求中解析 json ios afnetworking

ios - 在 UILabels 后面设置背景相机

android - 如何使用TeamCity构建我的React native 应用程序?