Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
Ios 如何使用MBRoute(Mapbox)获取MKPolyline(Mapkit)_Ios_Objective C_Mapkit_Mapbox_Mkpolyline - Fatal编程技术网

Ios 如何使用MBRoute(Mapbox)获取MKPolyline(Mapkit)

Ios 如何使用MBRoute(Mapbox)获取MKPolyline(Mapkit),ios,objective-c,mapkit,mapbox,mkpolyline,Ios,Objective C,Mapkit,Mapbox,Mkpolyline,我正在开发两个类似于Ola/Uber的应用程序,一个是驾驶员应用程序,另一个是骑手应用程序。driver应用程序使用mapbox进行导航,而rider应用程序使用简单的mapkit和google API。我的问题始于驾驶人在驾驶过程中重新选择路线,而骑手应用程序也必须跟踪驾驶人的新路径。现在应用的逻辑如下:在mapbox的didRerouteAlongRoute委托中,驱动程序应用程序通知服务器它已沿此特定MBRoute路由重新路由。服务器依次通知并将此信息传递给rider应用程序。问题是此MB

我正在开发两个类似于Ola/Uber的应用程序,一个是驾驶员应用程序,另一个是骑手应用程序。driver应用程序使用mapbox进行导航,而rider应用程序使用简单的mapkit和google API。我的问题始于驾驶人在驾驶过程中重新选择路线,而骑手应用程序也必须跟踪驾驶人的新路径。现在应用的逻辑如下:在mapbox的didRerouteAlongRoute委托中,驱动程序应用程序通知服务器它已沿此特定MBRoute路由重新路由。服务器依次通知并将此信息传递给rider应用程序。问题是此MBRoute数据类型在骑手端不可用,因为它使用mapkit而不是mapbox,我必须以某种方式转换此信息,以便在骑手端使用MKPolyline创建与驾驶员应用程序相同的新路线。感谢您的帮助


该api最初用于骑手端创建路线多段线:

最后,我设法满足了要求。它包括以下3个步骤:

  • 在驱动程序应用程序(使用mapbox框架)的DidReuterRouteAlongRoute委托中,创建一个包含新路线的纬度/经度字典的数组,如下所示:

    -(void)navigationViewController:(MBNavigationViewController*)navigationViewController didRerouteAlongRoute:(MBRoute*)route{
    
    CLLocationCoordinate2D *routeCoordinates = malloc(route.coordinateCount *sizeof(CLLocationCoordinate2D));
    [route getCoordinates:routeCoordinates];
    
    NSMutableArray *routeArray = [NSMutableArray new];
    for (NSValue *value in route.coordinates) {
    CLLocationCoordinate2D coordinate;
    [value getValue:&coordinate];
    NSDictionary *coDic = @{@"latitude" : [NSNumber numberWithDouble: coordinate.latitude],
                            @"longitude": [NSNumber numberWithDouble: coordinate.longitude]};
    [routeArray addObject:coDic];
                                          }
    }
    
  • 然后在序列化此数组(reRouteJSONString)后,通过API将此新路由的信息发送到服务器,如下所示:

    NSError *error;
    NSString *reRouteJSONString = @"";
    NSData *reRouteJSONData = [NSJSONSerialization dataWithJSONObject: routeArray options:NSJSONWritingPrettyPrinted error:&error];
    reRouteJSONString = [[NSString alloc] initWithData: reRouteJSONData encoding:NSUTF8StringEncoding] ;
    
  • 现在在rider应用程序中,按照以下方式操作此信息并形成新的路线多段线:

    -(void)makeReroutePolyline:(NSString*)serialisedString{
    
    MKMapView *mapView;
    mapView.delegate = self;
    
    NSError *jsonError;
    NSData *objectData = [serialisedString dataUsingEncoding:NSUTF8StringEncoding];
    NSArray *json = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:&jsonError];
    
    CLLocationCoordinate2D coordinates[json.count];
    for (NSInteger index = 0; index < json.count; index++) {
    CLLocationCoordinate2D coordinate = { [[json objectAtIndex:index][@"latitude"] doubleValue], [[json objectAtIndex:index][@"longitude"] doubleValue] };
    coordinates[index] = coordinate;
    }
    
    MKPolyline *routeLine;
    routeLine = [MKPolyline polylineWithCoordinates:coordinates count:json.count];
    [mapView addOverlay:routeLine];
    [mapView setVisibleMapRect:[routeLine boundingMapRect] edgePadding:UIEdgeInsetsZero animated:YES];
    
    }
    
    -(void)makeReroutePolyline:(NSString*)serialisedString{
    MKMapView*mapView;
    mapView.delegate=self;
    n错误*jsonError;
    NSData*objectData=[serialisedString数据使用编码:NSUTF8StringEncoding];
    NSArray*json=[NSJSONSerialization JSONObjectWithData:objectData选项:NSJSONReadingMutableContainers错误:&jsonError];
    CLLocationCoordinate2D坐标[json.count];
    对于(NSInteger index=0;index