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

标签 ios iphone google-maps google-maps-sdk-ios

我正尝试在对象移动时在 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/

相关文章:

ios - 带有 jwplayer 的 UIWebView

ios - 键值观察不允许枚举上的 Switch 语句

javascript - 为什么我的 AngularJS View 无法在 Cordova 中加载?

iphone - 如何让 iPhone 应用程序在后台完全运行

iphone - 单例和 KVO 的问题

ios - 无法使用类型为 '[NSObject : AnyObject]?' 的索引下标类型为 'String' 的值

iphone - UIView 中的 BezierPath 旋转

android - 如何通过改造发送 "clean"url

c# - 当我使用 ASP.NET MVC 5 在服务器上部署时出现 JSON 404 错误

android - 使用gps而不使用互联网连接在android中获取地址的纬度和经度