Ios 如何使用MBRoute(Mapbox)获取MKPolyline(Mapkit)
我正在开发两个类似于Ola/Uber的应用程序,一个是驾驶员应用程序,另一个是骑手应用程序。driver应用程序使用mapbox进行导航,而rider应用程序使用简单的mapkit和google API。我的问题始于驾驶人在驾驶过程中重新选择路线,而骑手应用程序也必须跟踪驾驶人的新路径。现在应用的逻辑如下:在mapbox的didRerouteAlongRoute委托中,驱动程序应用程序通知服务器它已沿此特定MBRoute路由重新路由。服务器依次通知并将此信息传递给rider应用程序。问题是此MBRoute数据类型在骑手端不可用,因为它使用mapkit而不是mapbox,我必须以某种方式转换此信息,以便在骑手端使用MKPolyline创建与驾驶员应用程序相同的新路线。感谢您的帮助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
该api最初用于骑手端创建路线多段线:最后,我设法满足了要求。它包括以下3个步骤:
-(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];
}
}
NSError *error;
NSString *reRouteJSONString = @"";
NSData *reRouteJSONData = [NSJSONSerialization dataWithJSONObject: routeArray options:NSJSONWritingPrettyPrinted error:&error];
reRouteJSONString = [[NSString alloc] initWithData: reRouteJSONData encoding:NSUTF8StringEncoding] ;
-(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