Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Google maps iOS SDK中跟踪用户路径_Ios_Objective C_Google Maps_Plot_Polyline - Fatal编程技术网

在Google maps iOS SDK中跟踪用户路径

在Google maps iOS SDK中跟踪用户路径,ios,objective-c,google-maps,plot,polyline,Ios,Objective C,Google Maps,Plot,Polyline,我一直在尝试在用户开始旅行后绘制从一个点到另一个点的路径。我使用谷歌地图iOS SDK和GMSPolyLine在用户开始旅行后绘制路径 Am使用locationManager:didUpdateLocation跟踪行程,并在用户更新其位置后绘制路线。当我们搜索从一个点到另一个点的路径时,我无法像谷歌地图那样正确绘制路径。我添加了屏幕截图,以显示发生的差异 我的应用程序: 上面是我的应用程序的屏幕截图,你可以注意到转弯没有正确绘制 所需的输出: 有谁能告诉我绘制一条类似于谷歌地图的整洁路径的最

我一直在尝试在用户开始旅行后绘制从一个点到另一个点的路径。我使用谷歌地图iOS SDK和GMSPolyLine在用户开始旅行后绘制路径

Am使用
locationManager:didUpdateLocation
跟踪行程,并在用户更新其位置后绘制路线。当我们搜索从一个点到另一个点的路径时,我无法像谷歌地图那样正确绘制路径。我添加了屏幕截图,以显示发生的差异

我的应用程序:

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

所需的输出:


有谁能告诉我绘制一条类似于谷歌地图的整洁路径的最佳实践吗?

之所以会出现这种情况,是因为您的位置不是不断更新的,当更新时,多段线是在两点之间笔直绘制的,所以当您获得调用api的下一个位置时,您必须进行一次思考

当您调用此api时,您将获得从中传递的两点之间的路由数组,从而获得最佳路由(可能是第一条路由)。从该布线字典中提取概述\u多段线对象概述\u多段线对象是解码的两点之间位置点的纬度和经度数组

当您通过以下方法转换它时,您就得到了所需的精确多段线

有两种方法可以解码多段线

第一种方法


这可能会对您有所帮助。

在某些情况下,应用程序在characterAtIndex的decodePolyLine方法中崩溃***由于未捕获的异常“NSRangeException”终止应用程序,原因:'-[\u NSCFString characterAtIndex:::]:范围或索引超出范围',如果在decodePolyLine方法的while循环中,我将while(索引#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];