在Google地图iOS SDK中跟踪用户path

在他开始旅行之后,我一直在试图从一个地方到另一个地方绘制用户path。 我使用Google地图iOS SDK和GMSPolyLine来绘制用户开始旅行之后的path。

正在使用locationManager:didUpdateLocation跟踪旅行,并在用户更新其位置后绘制线条。 当我们search从一个点到另一个点的path时,无法正确地绘制path,因为它发生在Google地图中。 我已经添加了截屏的差异发生。

我的应用程序: https : //www.dropbox.com/s/h1wjedgcszc685g/IMG_6555.png?dl = 0

以上是我的应用程序的截图,你可以注意到,转弯没有正确绘制

需要输出: https : //www.dropbox.com/s/poqaeadh1g93h6u/IMG_6648.png?dl = 0

任何人都可以指向我的最佳做法,绘制类似于谷歌地图的整洁path?

发生这种情况是因为你的位置不是连续更新的,当它更新多段线时,在两点之间画直线,所以当你得到下一个你称之为api的位置时,你必须做一个想法。

当你调用这个API的时候,你得到了你从最佳路线(可能的第一条路线)通过的两点之间的路线数组。 从该路由字典中提取overview_polyline对象。 overview_polyline对象是解码你的两点之间的位置点的纬度和经度数组。

当你通过下面的方法转换它时,你有你想要的确切的折线

有两种方法来解码折线

第一种方法

 #pragma mark #pragma mark - decode polyline // these function is given by client -(void) decodePoly:(NSString *)encoded Color:(UIColor *)color { GMSMutablePath *path = [[GMSMutablePath alloc] init]; // NSString *encoded=@"g|vfEmo{gMz@h@PJNFRJNDXHJ@b@FZ@F?L?XAVCr@Kj@Ut@]zAi@HETE^IVELCPANAhCYHAHCHCHCHEh@i@"; NSUInteger index = 0, len = encoded.length; int lat = 0, lng = 0; while (index < (len - 2)) { int b, shift = 0, result = 0; do { // b = encoded.charAt(index++) - 63; b = [encoded characterAtIndex:index++] - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = [encoded characterAtIndex:index++] - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; CLLocation *loc = [[CLLocation alloc] initWithLatitude:((double) lat / 1E5) longitude:((double) lng / 1E5)]; [path addCoordinate:loc.coordinate]; } GMSPolyline *polyline = [GMSPolyline polylineWithPath:path]; // Add the polyline to the map. polyline.strokeColor = color; polyline.strokeWidth = 5.0f; polyline.map = [self getGoogleMap]; } 

第二种方法

 GMSPolyline *polyline =[GMSPolyline polylineWithPath:[GMSPath pathFromEncodedPath:"your encoded string"]]; // Add the polyline to the map. polyline.strokeColor = color; polyline.strokeWidth = 5.0f; polyline.map = [self getGoogleMap]; 

愿这件事帮助你。