An easiest way is that you can first:
1) Calculate total distance of the path using GMSGeometryDistance, by calculating the distance between every two subsequent points by GMSGeometryDistance function, then summing all the distance.
2) Then you calculate again, and summing in each step. When the sum is about half of the total distance, then you are at the middle point.
Sample code is as following:
func findTotalDistanceOfPath(path: GMSPath) -> Double {
let numberOfCoords = path.count()
var totalDistance = 0.0
if numberOfCoords > 1 {
var index = 0 as UInt
while index < numberOfCoords{
//1.1 cal the next distance
var currentCoord = path.coordinateAtIndex(index)
var nextCoord = path.coordinateAtIndex(index + 1)
var newDistance = GMSGeometryDistance(currentCoord, nextCoord)
totalDistance = totalDistance + newDistance
index = index + 1
}
}
return totalDistance
}
func findMiddlePointInPath(path: GMSPath ,totalDistance distance:Double) -> CLLocationCoordinate2D? {
let numberOfCoords = path.count()
let halfDistance = distance/2
let threadhold = 10 //10 meters
var midDistance = 0.0
if numberOfCoords > 1 {
var index = 0 as UInt
while index < numberOfCoords{
//1.1 cal the next distance
var currentCoord = path.coordinateAtIndex(index)
var nextCoord = path.coordinateAtIndex(index + 1)
var newDistance = GMSGeometryDistance(currentCoord, nextCoord)
midDistance = midDistance + newDistance
if fabs(midDistance - halfDistance) < threadhold { //Found the middle point in route
return nextCoord
}
index = index + 1
}
}
return nil //Return nil if we cannot find middle point in path for some reason
}
There is more to optimize the function. I wrote a detail answer in Swift in here