如何使用ios中的skobbler计算从源到目的地的路线?

时间:2016-02-22 05:03:47

标签: ios

SKRouteSettings用于设置路线条件,包括开始坐标,endCoordinates等。

之后,SKRoutingService通过从calculateRoute上方传递路线来调用委托方法SKRouteSettings。该方法应该调用didFinishRouteCalculationWithInfo的{​​{1}}或routingServiceDidFailRouteCalculation方法,但不调用任何方法。

任何人都可以帮我确定我哪里错了吗?

1 个答案:

答案 0 :(得分:0)

试试这个......

#import <SKMaps/SKMaps.h>
 @implementation RoutingViewController<SKRoutingDelegate>
     - (void)viewDidLoad{
     [super viewDidLoad];
     SKMapView *mapView =[[SKMapView alloc] initWithFrame:CGRectMake( 0.0f, 0.0f,  CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) )];
     [SKRoutingService sharedInstance].routingDelegate = self; // set for receiving routing callbacks
     [SKRoutingService sharedInstance].mapView = mapView; // use the map view instance for route rendering
     SKRouteSettings* route = [[SKRouteSettings alloc]init];
     route.startCoordinate=CLLocationCoordinate2DMake(37.447692, -122.166016);
     route.destinationCoordinate=CLLocationCoordinate2DMake(37.437964, -122.141147);
     route.shouldBeRendered = YES; // If NO, the route will not be rendered.
     route.routeMode = SKRouteCarFastest;
     route.maximumReturnedRoutes = 1;
     SKRouteRestrictions routeRestrictions = route.routeRestrictions;
     routeRestrictions.avoidHighways = YES;
     route.routeRestrictions = routeRestrictions;
     [[SKRoutingService sharedInstance] calculateRoute:route];
     }
     - (void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation*)routeInformation{
     NSLog(@"Route is calculated.");
     [routingService zoomToRouteWithInsets:UIEdgeInsetsZero duration:1]; // zoom to current route
     }
     - (void)routingServiceDidFailRouteCalculation:(SKRoutingService *)routingService{
     NSLog(@"Route calculation failed.");
     }
     @end