gpt4 book ai didi

ios - 如何在添加坐标之前检查 GMSMutablePath 中是否存在坐标

转载 作者:行者123 更新时间:2023-11-28 19:30:42 27 4
gpt4 key购买 nike

我正尝试在对象移动时在 Google map 上绘制多段线,有时发送的坐标可能会重复。我想防止将重复的坐标添加到 GMSMutablePath。反正这能实现吗?

目前我使用以下方法将坐标添加到 GMSMutablePath。它还会添加重复值!

self.path.addLatitude(coordinate.latitude, longitude: coordinate.longitude)

最佳答案

GoogleMaps SDK 中做了一些挖掘之后,我找到了这个解决方案。它可能不是完美的,但您可以试一试。

您可以使用 GMSMutablePathcoordinate(at:index) 方法遍历路径的所有坐标

迭代 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)
}

关于ios - 如何在添加坐标之前检查 GMSMutablePath 中是否存在坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45141344/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com