ios - 如何计算 GMSMutablePath iOS 中覆盖的总距离

标签 ios iphone swift google-maps gmsmapview

我有一条由用户及其坐标点行走的完整路线。

i have create path of it.

let path = GMSMutablePath()
path.add(CLLocationCoordinate2D(latitude: latNew, longitude: longNew))

//在此处添加多个位置。

Showing path to map.

let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 5.0;
polyline.strokeColor = UIColor.blue
let styles = [GMSStrokeStyle.solidColor(UIColor.black), GMSStrokeStyle.solidColor(UIColor.clear)]
let lengths = [2, 2];
polyline.spans = GMSStyleSpans(polyline.path!, styles, lengths as [NSNumber], kGMSLengthRhumb)
polyline.geodesic = true
polyline.map = self.viewGMap

现在我只想计算这条路线所覆盖的总距离。

怎么做?

最佳答案

你可以这样找到长度:

// Geodesic length, in meters, along Projected segments
NSLog(@"Lenght Length Projected=%f",[path lengthOfKind:kGMSLengthProjected]);

// Rhumb length, in meters, along rhumb (straight line) segments
NSLog(@"Lenght Length Rhumb=%f",[path lengthOfKind:kGMSLengthRhumb]);

// Length in projected space, along Geodesic segments.
NSLog(@"Lenght Length Geodesic=%f",[path lengthOfKind:kGMSLengthGeodesic]);

关于ios - 如何计算 GMSMutablePath iOS 中覆盖的总距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41735317/

相关文章:

iPhone Storyboard - 分配类以在 Storyboard中查看 Controller

iphone - 如何将一张图片分割成多个部分

iOS - 在更新到新版本时保留旧的 sqlite 数据库

ios - 在 iOS 上的 Swift 中将字节流保存到文件

ios - 扫描功能不适用于 Action Extension(没有打开相机进行扫描)

ios - 允许您为同一键添加多个对象的数据结构

iphone - 如何删除默认光泽图标效果?

iphone - didSelectRowAtIndexPath 没有被调用

IOS swift 我如何检查删除 super View 或在 subview 中关闭它

ios - 如何在 Swift 中将数组存储到 PFFile 中?