我有一条完整的路线,由用户及其坐标点走过。
我创造了它的路径。
let path = GMSMutablePath()
path.add(CLLocationCoordinate2D(latitude: latNew, longitude: longNew))
//在这里添加多个位置。
显示地图路径。
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
现在我想计算此路线所涵盖的总距离。
怎么做?
答案 0 :(得分:0)
你可以找到这样的长度:
// 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]);