【问题标题】:direction between two markers in swiftswift中两个标记之间的方向
【发布时间】:2016-06-18 11:51:10
【问题描述】:

我想快速从谷歌地图获取方向。 在我的应用程序中,用户可以使用 LongTouch 制作两个标记,我想在标记之间显示方向,并且我还获得了每个标记的纬度和经度。 我是业余爱好者,找不到此代码。

func mapView(mapView: GMSMapView, didLongPressAtCoordinate coordinate: CLLocationCoordinate2D) {
    if counterMarker < 2
    {
        counterMarker += 1
        let marker = GMSMarker(position: coordinate)
        marker.appearAnimation = kGMSMarkerAnimationPop

        marker.map = mapView
        marker.position.latitude = coordinate.latitude
        marker.position.longitude = coordinate.longitude
        latitudeMarker = marker.position.latitude
        longitudeMarker = marker.position.longitude

        print(latitudeMarker)
        print(longitudeMarker)
        print("ok")

}
    }

如何使用谷歌地图获取方向和时间?

【问题讨论】:

    标签: swift google-maps direction


    【解决方案1】:

    您可以尝试使用Google Maps Directions API,它是一种使用 HTTP 请求计算位置之间方向的服务。

    您可以将您的两个标记设置为起点和终点参数,即您希望计算方向的地址、文本纬度/经度值或地点 ID。

    • 如果您传递地址,路线服务会对该字符串进行地理编码并将其转换为纬度/经度坐标以计算路线。

    origin=24+Sussex+Drive+Ottawa+ON

    • 如果您传递坐标,则它们将用于计算方向时不变。确保纬度和经度值之间没有空格。

    原点=41.43206,-81.38992

    有关 Directions API 的更多信息,请阅读上面的文档链接。

    您也可以尝试检查这个相关的 SO 问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      相关资源
      最近更新 更多