我正在尝试在Google地图上绘制折线作为对象行进,有时发送的坐标可能会重复。我想防止将重复坐标添加到GMSMutablePath。无论如何这可以实现吗?
目前,我使用以下方法将坐标添加到GMSMutablePath。它还添加了重复值!
self.path.addLatitude(coordinate.latitude, longitude: coordinate.longitude)
答案 0 :(得分:2)
在GoogleMaps SDK
进行一些挖掘后,我找到了这个解决方案。它可能不是完美的,但你可以尝试一下。
您可以使用coordinate(at:index)
GMSMutablePath
方法遍历路径的所有坐标
迭代GMSMutablePath
坐标。
//Here path is your GMSMutablePath
for i in 0..<path.count() {
let coordinate = path.coordinate(at: i)
//The coordinate received is a CLLocationCoordinate2D type from which you can get the latitude and longitude.
//Here check the coordinate latitude and longitude is same as your received coordinate, make a return else add to your path.
//You can also keep a flag variable and at the end of all iterations, you can check whether the coordinate is present or not.
print(coordinate)
}