我有这段代码,但由于某种原因,它只是在 2 个点(第一个和最后一个点)之间绘制了一条路线,而忽略了所有其他点,即 [index == 1 to index == n-1 ]
输出:仅在 2 个标记之间路由
预期输出:所有标记之间的路由(5 个标记)
有没有人知道我的代码有什么问题?
func getDotsToDrawRoute(positions : [CLLocationCoordinate2D], completion: @escaping(_ path : GMSPath) -> Void) {
if positions.count > 1 {
let origin = positions.first
let destination = positions.last
var wayPoints = ""
for point in positions {
wayPoints = wayPoints.characters.count == 0 ? "\(point.latitude),\(point.longitude)" : "\(wayPoints)|\(point.latitude),\(point.longitude)"
}
print("this is fullPath :: \(wayPoints)")
let request = "https://maps.googleapis.com/maps/api/directions/json"
let parameters : [String : String] = ["origin" : "\(origin!.latitude),\(origin!.longitude)", …Run Code Online (Sandbox Code Playgroud)