多个纬度经度之间的Google Map绘制折线

爱科技

我有一个经度和纬度数组,我想使用这些数据绘制折线。

数组数据如下

[
     {
        address = "Gota, Godrej Garden City Road, Ahmedabad, India, 382481 ",
        city = Ahmedabad,
        latitude = "23.10104251103548",
        longitude = "72.54941169820619",
        street = "Godrej Garden City Road",
     },
     {
        address = "Aaryan Eureka Opposite Shayona Shikhar, Vandemataram Rd, Gota, Ahmedabad, Gujarat 382481",
        city = Ahmedabad,
        latitude = "23.09644251103548",
        longitude = "72.54801169820619",
        street = "Vandemataram Rd",
     },
     ....// Hundreds of records
]

到目前为止我尝试过的代码

let path = GMSMutablePath()
    for mapData in arrMapData {
        path.add(CLLocationCoordinate2D(latitude: mapData.latitude ?? 0.0, longitude: mapData.longitude ?? 0.0))
    }
    let polyline = GMSPolyline(path: path)
    polyline.strokeWidth = 3.0
    polyline.strokeColor = .black
    polyline.map = mapView // Google MapView

    // Creates a marker in the center of the map.
    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2D(latitude: arrMapData[0].latitude ?? 0.0, longitude: arrMapData[0].longitude ?? 0.0)
    marker.icon = UIImage(named: AppImages.Pin_red)
    marker.title = sourceTitle
    marker.snippet = sourceSnippet
    marker.map = mapView

    let marker1 = GMSMarker()
    marker1.position = destination
    marker1.icon = UIImage(named: AppImages.Map_pin_orange)
    marker1.title = destinationTitle
    marker1.snippet = destinationSnippet
    marker1.map = mapView

我知道Google Direction API,但是我不需要调用该api,因为我已经拥有了所有这些经度和纬度数据...甚至为所有一百条记录调用direction api也不可行。

我上面的代码没有给我任何类型的错误。它在地图上标出了两个对我来说似乎正确的引脚[源目标详细信息是从数组的第0个索引对象添加的,而数组的最后一个索引对象是添加的]。

在此处输入图片说明

但不会在地图上添加折线。我正在寻找解决方案。谢谢!

崔阮

从您的代码中,我将数组lat和lng修改为以下功能

func drawPolyline(){
        let location: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 23.10104251103548, longitude: 72.54941169820619)
        let camera = GMSCameraPosition.camera(withTarget: location, zoom: 18)
        self.mapContentView.mapView.animate(to: camera)

        let arrLat = [23.10104251103548, 23.09644251103548, 23.08644251103548, 23.07644251103548, 23.06644251103548]
        let arrLng = [72.54941169820619, 72.54801169820619, 72.54701169820619, 72.54601169820619, 72.54501169820619]
        let path = GMSMutablePath()
        for i in 0..<arrLat.count {
            path.add(CLLocationCoordinate2D(latitude: arrLat[i], longitude: arrLng[i]))
        }
        let polyline = GMSPolyline(path: path)
        polyline.strokeWidth = 3.0
        polyline.strokeColor = .black
        polyline.map = self.mapContentView.mapView

        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: 23.10104251103548, longitude: 72.54941169820619)
        marker.icon = UIImage(named: "ic_marker")
        marker.title = "A"
        marker.snippet = "ABC"
        marker.map = self.mapContentView.mapView

        let marker1 = GMSMarker()
        marker1.position = CLLocationCoordinate2D(latitude: 23.06644251103548, longitude: 72.54501169820619)
        marker1.icon = UIImage(named: "ic_marker")
        marker1.title = "B"
        marker1.snippet = "EFG"
        marker1.map = self.mapContentView.mapView
    }

结果在这里

我认为您应该先在应用中尝试一些经纬度示例。如果有效,则问题出在您的解析数据上。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在Google Map上绘制虚线折线-Android

来自分类Dev

在多个标记之间绘制折线

来自分类Dev

Google Map API给出的经度/纬度单位

来自分类Dev

如何在Android Google Map V2上放置标记/绘制经度和纬度

来自分类Dev

如何在Google Map中标记纬度,经度?

来自分类Dev

Google Map android中的经度和纬度点集群的中心

来自分类Dev

Android Google Map摆脱折线

来自分类Dev

Google地图:实时绘制和更新折线

来自分类Dev

在Google地图上绘制多条折线

来自分类Dev

在Google Maps Streetview上绘制折线

来自分类Dev

Google折线图绘制问题

来自分类Dev

绘制带有多个缺失值的Google折线图

来自分类Dev

如何绘制geoAlbersUsa()投影的经度纬度坐标?

来自分类Dev

在地图上绘制纬度经度坐标

来自分类Dev

在 SVG 中绘制纬度和经度坐标

来自分类Dev

如何使用Google Map API在PHP中获取当前的经度和纬度?

来自分类Dev

拖放后将Google Map Marker的新纬度和经度保存到文本框中

来自分类Dev

从Google Map中的路线查找起点查找经度和纬度

来自分类Dev

如何获取在Android Google Map中使用经度和纬度设置的确切视图

来自分类Dev

在特定纬度和经度上显示带有标记的嵌入式Google Map iframe

来自分类Dev

如何在Google Map API中获取基于纬度和经度的最接近的地标?

来自分类Dev

Google Map Geocode API返回的纬度/经度键不正确

来自分类Dev

拖放后将Google Map Marker的新纬度和经度保存到文本框中

来自分类Dev

如何在iOS中使用Google Map API获取mapView上触摸位置的纬度和经度

来自分类Dev

PHP:如何从数据库中设置中心Google Map的纬度和经度?

来自分类Dev

如何在PHP中使用Google Map API获取已创建多边形的纬度,经度

来自分类Dev

如何使用Google Map API在PHP中获取当前的经度和纬度?

来自分类Dev

尝试使用Google Map API获取经度和纬度时显示ZERO_RESULTS

来自分类Dev

如何根据纬度/经度在D3地图上的两个点之间绘制线/链接?

Related 相关文章

  1. 1

    在Google Map上绘制虚线折线-Android

  2. 2

    在多个标记之间绘制折线

  3. 3

    Google Map API给出的经度/纬度单位

  4. 4

    如何在Android Google Map V2上放置标记/绘制经度和纬度

  5. 5

    如何在Google Map中标记纬度,经度?

  6. 6

    Google Map android中的经度和纬度点集群的中心

  7. 7

    Android Google Map摆脱折线

  8. 8

    Google地图:实时绘制和更新折线

  9. 9

    在Google地图上绘制多条折线

  10. 10

    在Google Maps Streetview上绘制折线

  11. 11

    Google折线图绘制问题

  12. 12

    绘制带有多个缺失值的Google折线图

  13. 13

    如何绘制geoAlbersUsa()投影的经度纬度坐标?

  14. 14

    在地图上绘制纬度经度坐标

  15. 15

    在 SVG 中绘制纬度和经度坐标

  16. 16

    如何使用Google Map API在PHP中获取当前的经度和纬度?

  17. 17

    拖放后将Google Map Marker的新纬度和经度保存到文本框中

  18. 18

    从Google Map中的路线查找起点查找经度和纬度

  19. 19

    如何获取在Android Google Map中使用经度和纬度设置的确切视图

  20. 20

    在特定纬度和经度上显示带有标记的嵌入式Google Map iframe

  21. 21

    如何在Google Map API中获取基于纬度和经度的最接近的地标?

  22. 22

    Google Map Geocode API返回的纬度/经度键不正确

  23. 23

    拖放后将Google Map Marker的新纬度和经度保存到文本框中

  24. 24

    如何在iOS中使用Google Map API获取mapView上触摸位置的纬度和经度

  25. 25

    PHP:如何从数据库中设置中心Google Map的纬度和经度?

  26. 26

    如何在PHP中使用Google Map API获取已创建多边形的纬度,经度

  27. 27

    如何使用Google Map API在PHP中获取当前的经度和纬度?

  28. 28

    尝试使用Google Map API获取经度和纬度时显示ZERO_RESULTS

  29. 29

    如何根据纬度/经度在D3地图上的两个点之间绘制线/链接?

热门标签

归档