Commit 90be2393 authored by Deployer's avatar Deployer

Added instructions to routings

parent a8b17c71
...@@ -166,6 +166,18 @@ ...@@ -166,6 +166,18 @@
*/ */
- (void)calculateDirections:(nonnull NSArray<CSRoutePair *> *)routePairs withCompletionHandler:(nonnull CSDirectionCompletionHandler)completionHandler; - (void)calculateDirections:(nonnull NSArray<CSRoutePair *> *)routePairs withCompletionHandler:(nonnull CSDirectionCompletionHandler)completionHandler;
/**
* This method calculates directions with verbal instructions using car profile between a source and a destination.
*
* Up to 100 pairs of source and destionation points can be provided to calculate a multiple step routing.
@param routePairs An array of CSRoutePair consisting of source and destination points.
@param locale The locale for instruction. Currently supports "en" and "fa"
@param completionHandler This handler is called when the process of fetching direction
* results is completed. The block will be called on the main_queue.
@see CSRoutePair.h
*/
- (void)calculateDirectionsWithInstructionsForRoutePairs:(nonnull NSArray<CSRoutePair *> *)routePairs locale:(nonnull NSLocale *)locale withCompletionHandler:(nonnull CSDirectionCompletionHandler)completionHandler;
/** /**
* This method calculates distance using car profile between a source and a destination. * This method calculates distance using car profile between a source and a destination.
......
...@@ -302,11 +302,15 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR ...@@ -302,11 +302,15 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR
- (void)calculateDirections:(NSArray<CSRoutePair *> *)routePairs - (void)calculateDirections:(NSArray<CSRoutePair *> *)routePairs
withCompletionHandler:(CSDirectionCompletionHandler)completionHandler { withCompletionHandler:(CSDirectionCompletionHandler)completionHandler {
[self fetchDirectionOrDistance:kDirection forRoutePairs:routePairs withCompletionHandler:completionHandler]; [self fetchDirectionOrDistance:kDirection forRoutePairs:routePairs withInstructions:NO locale:nil withCompletionHandler:completionHandler];
}
- (void)calculateDirectionsWithInstructionsForRoutePairs:(NSArray<CSRoutePair *> *)routePairs locale:(NSLocale *)locale withCompletionHandler:(CSDirectionCompletionHandler)completionHandler {
[self fetchDirectionOrDistance:kDirection forRoutePairs:routePairs withInstructions:YES locale:locale withCompletionHandler:completionHandler];
} }
- (void)calculateDistance:(NSArray<CSRoutePair *> *)routePairs withCompletionHandler:(CSDirectionCompletionHandler)completionHandler { - (void)calculateDistance:(NSArray<CSRoutePair *> *)routePairs withCompletionHandler:(CSDirectionCompletionHandler)completionHandler {
[self fetchDirectionOrDistance:kDistance forRoutePairs:routePairs withCompletionHandler:completionHandler]; [self fetchDirectionOrDistance:kDistance forRoutePairs:routePairs withInstructions:NO locale:nil withCompletionHandler:completionHandler];
} }
typedef enum { typedef enum {
...@@ -314,7 +318,7 @@ typedef enum { ...@@ -314,7 +318,7 @@ typedef enum {
kDistance kDistance
} DirectionOrDistance; } DirectionOrDistance;
- (void)fetchDirectionOrDistance:(DirectionOrDistance)option forRoutePairs:(NSArray<CSRoutePair *> *)routePairs withCompletionHandler:(CSDirectionCompletionHandler)completionHandler { - (void)fetchDirectionOrDistance:(DirectionOrDistance)option forRoutePairs:(NSArray<CSRoutePair *> *)routePairs withInstructions:(BOOL)shouldGetInstructions locale:(NSLocale *)locale withCompletionHandler:(CSDirectionCompletionHandler)completionHandler {
NSString *pointsStr = @""; NSString *pointsStr = @"";
for (int i = 0; i < MIN(routePairs.count, 100); i++) { for (int i = 0; i < MIN(routePairs.count, 100); i++) {
...@@ -335,6 +339,9 @@ typedef enum { ...@@ -335,6 +339,9 @@ typedef enum {
if (pointsStr.length > 0) { if (pointsStr.length > 0) {
urlStr = [urlStr stringByAppendingString:pointsStr]; urlStr = [urlStr stringByAppendingString:pointsStr];
} }
if (locale.languageCode) {
urlStr = [urlStr stringByAppendingFormat:@"?instructions=%@&locale=%@", shouldGetInstructions ? @"true" : @"false", locale.languageCode];
}
__weak CSMapKit *weakSelf = self; __weak CSMapKit *weakSelf = self;
[self responseFromURLString:urlStr completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { [self responseFromURLString:urlStr completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import <JSONModel/JSONModel.h> #import <JSONModel/JSONModel.h>
#import "CSBoundingBox.h" #import "CSBoundingBox.h"
#import "CSRouteInstruction.h"
@protocol CSRoute; @protocol CSRoute;
...@@ -39,6 +40,11 @@ ...@@ -39,6 +40,11 @@
*/ */
@property (nonatomic, strong, nullable) NSArray<CLLocation *> <Optional> *points; @property (nonatomic, strong, nullable) NSArray<CLLocation *> <Optional> *points;
/**
* Verbal representation of the route.
*/
@property (nonatomic, strong, nullable) NSArray<CSRouteInstruction *> <Optional, CSRouteInstruction> *instructions;
@end @end
typedef void (^CSDirectionCompletionHandler)(NSArray<CSRoute *> * __nullable routes, NSError * __nullable error); typedef void (^CSDirectionCompletionHandler)(NSArray<CSRoute *> * __nullable routes, NSError * __nullable error);
......
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
@implementation CSRoute @implementation CSRoute
- (NSTimeInterval)time {
return _time / 1000;
}
- (void)setBoundingBoxWithNSArray:(NSArray *)array { - (void)setBoundingBoxWithNSArray:(NSArray *)array {
if (array && array.count == 4) { if (array && array.count == 4) {
CLLocationCoordinate2D ne = CLLocationCoordinate2DMake([array[3] doubleValue], [array[2] doubleValue]); CLLocationCoordinate2D ne = CLLocationCoordinate2DMake([array[3] doubleValue], [array[2] doubleValue]);
......
//
// CSRouteInstruction.h
// CedarMaps
//
// Created by Saeed Taheri on 1/13/18.
//
#import <JSONModel/JSONModel.h>
@import CoreLocation;
@protocol CSRouteInstruction;
typedef NS_ENUM(NSUInteger, CSInstructionSign) {
CSInstructionSignKeepLeft = -7,
CSInstructionSignTurnSharpLeft = -3,
CSInstructionSignTurnLeft = -2,
CSInstructionSignTurnSlightLeft = -1,
CSInstructionSignContinue = 0,
CSInstructionSignTurnSlightRight = 1,
CSInstructionSignTurnRight = 2,
CSInstructionSignTurnSharpRight = 3,
CSInstructionSignFinish = 4,
CSInstructionSignReachedVia = 5,
CSInstructionSignUseRoundabout = 6,
CSInstructionSignKeepRight = 7
};
/**
* Verbal representation of a route section in routing.
*/
@interface CSRouteInstruction : JSONModel
/**
Distance in a route section in meters using car profile.
*/
@property (nonatomic, assign) CLLocationDistance distance;
/**
ETA for a route in seconds using car profile.
*/
@property (nonatomic, assign) NSTimeInterval time;
/**
Main street name in the route section.
*/
@property (nonatomic, strong) NSString *streetName;
/**
Textual instruction of route section.
*/
@property (nonatomic, strong) NSString *text;
/**
An array of indeces; these indeces can be looked up in CSRoute `points` property. It shows locations included in this section.
*/
@property (nonatomic, strong) NSArray<NSNumber *> *interval;
/**
Traffic sign of current section.
*/
@property (nonatomic, assign) CSInstructionSign sign;
@end
//
// CSRouteInstruction.m
// CedarMaps
//
// Created by Saeed Taheri on 1/13/18.
//
#import "CSRouteInstruction.h"
@implementation CSRouteInstruction
- (NSTimeInterval)time {
return _time / 1000;
}
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{
@"streetName": @"street_name"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
}
@end
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
{ {
[[CSMapKit sharedMapKit] setCredentialsWithClientID:@"YOUR_CLIENT_ID" clientSecret:@"YOUR_CLIENT_SECRET"]; [[CSMapKit sharedMapKit] setCredentialsWithClientID:@"YOUR_CLIENT_ID" clientSecret:@"YOUR_CLIENT_SECRET"];
[[CSMapKit sharedMapKit] prepareMapTiles:^(BOOL isReady, NSError * _Nullable error) { [[CSMapKit sharedMapKit] prepareMapTiles:^(BOOL isReady, NSError * _Nullable error) {
}]; }];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment