GLRoute
Objective-C
@interface GLRoute : NSObject
Swift
class GLRoute : NSObject
GLRoute
is a class that loads and models route data, providing information about maneuvers, lengths, durations, and more.
-
Initializes a route with the specified JSON data.
Declaration
Objective-C
- (instancetype _Nullable)initWithJSON:(nonnull NSString *)json;
Swift
init?(json: String)
Parameters
json
The JSON data returned from Valhalla
Return Value
A new instance of GLRoute or nil, if data is invalid
-
Finds the index where the given point should be inserted into the array of reference points.
Declaration
Objective-C
+ (NSUInteger)findInsertionIndex:(nonnull GLMapPoint *)point points:(nonnull const GLMapPoint *)points pointsCount:(NSInteger)pointsCount;
Swift
class func findInsertionIndex(_ point: UnsafeMutablePointer<GLMapPoint>, points: UnsafePointer<GLMapPoint>, pointsCount: Int) -> UInt
Parameters
point
On input, defines the point to insert; on output, contains the point located on the route.
points
An array of reference GLMapPoints.
pointsCount
The number of points in the array.
Return Value
NSNotFound if the given point is too far from the track; otherwise, the index where the point should be inserted.
-
Returns track data that can be used to display the route’s track with the specified color.
Declaration
Objective-C
- (GLMapTrackData *_Nullable)trackDataWithColor:(GLMapColor)trackColor;
Swift
func trackData(with trackColor: GLMapColor) -> GLMapTrackData?
Parameters
trackColor
The color to use for the route track.
Return Value
The track data for the route.
-
Returns track data that can be used to display the route’s track with a gradient generated by the specified color block.
Declaration
Objective-C
- (GLMapTrackData *_Nullable)trackDataWithCallback: (nonnull GLMapTrackDataColorBlock)colorBlock;
Swift
func trackData(callback colorBlock: @escaping GLMapTrackDataColorBlock) -> GLMapTrackData?
Parameters
colorBlock
The block used to generate the gradient.
Return Value
The track data for the route.
-
Returns the route target point at the specified index.
Declaration
Objective-C
- (GLRoutePoint)targetPointAtIndex:(NSUInteger)index;
Swift
func targetPoint(at index: UInt) -> GLRoutePoint
Parameters
index
The index of the target point in the range [0, targetPointsCount).
Return Value
The target point at the specified index.
-
The number of reference points in the route.
Declaration
Objective-C
@property (readonly) NSUInteger targetPointsCount;
Swift
var targetPointsCount: UInt { get }
-
Returns the length of the leg at the specified index.
Declaration
Objective-C
- (double)lengthOfLeg:(NSUInteger)index;
Swift
func length(ofLeg index: UInt) -> Double
Parameters
index
The index of the leg in the range [0, legsCount).
Return Value
The length of the leg at the specified index.
-
Returns the duration of the leg at the specified index.
Declaration
Objective-C
- (double)durationOfLeg:(NSUInteger)index;
Swift
func duration(ofLeg index: UInt) -> Double
Parameters
index
The index of the leg in the range [0, legsCount).
Return Value
The length of the leg at the specified index.
-
The total number of legs in the route.
Declaration
Objective-C
@property (readonly) NSUInteger legsCount;
Swift
var legsCount: UInt { get }
-
The total length of the route in meters.
Declaration
Objective-C
@property (readonly) double length;
Swift
var length: Double { get }
-
The estimated duration of the route in seconds.
Declaration
Objective-C
@property (readonly) double duration;
Swift
var duration: Double { get }
-
Returns the maneuver following the specified maneuver.
Declaration
Objective-C
- (GLRouteManeuver *_Nullable)getNextManeuver: (nonnull GLRouteManeuver *)maneuver;
Swift
func getNextManeuver(_ maneuver: GLRouteManeuver) -> GLRouteManeuver?
Parameters
maneuver
The reference maneuver.
Return Value
The next maneuver in the route, or
nil
if there are no more maneuvers. -
Returns the maneuver preceding the specified maneuver.
Declaration
Objective-C
- (GLRouteManeuver *_Nullable)getPreviousManeuver: (nonnull GLRouteManeuver *)maneuver;
Swift
func getPreviousManeuver(_ maneuver: GLRouteManeuver) -> GLRouteManeuver?
Parameters
maneuver
The reference maneuver.
Return Value
The previous maneuver in the route, or
nil
if there are no previous maneuvers. -
Finds the nearest point on the route and updates the input point and height with the result.
Declaration
Objective-C
- (void)findNearestPoint:(nonnull GLMapPoint *)point height:(nonnull CGFloat *)height;
Swift
func findNearestPoint(_ point: UnsafeMutablePointer<GLMapPoint>, height: UnsafeMutablePointer<CGFloat>)
Parameters
point
On input, contains the reference point; on output, contains the nearest point on the route.
height
On output, contains the height at the nearest point or
NAN
if height data is not available. -
Enumerates the points in the specified maneuver and calls the enumerator block for each point.
Declaration
Objective-C
- (void)enumManeuverPoints:(nonnull GLRouteManeuver *)maneuver withBlock:(nonnull GLRouteEnumPointsBlock)block;
Swift
func enumManeuverPoints(_ maneuver: GLRouteManeuver, with block: @escaping GLRouteEnumPointsBlock)
Parameters
maneuver
The maneuver to enumerate.
block
The enumerator block to call for each point.
-
Enumerates the points from the specified starting point to the end of the route and calls the enumerator block for each point.
Declaration
Objective-C
- (void)enumPointsFrom:(NSUInteger)startPoint withBlock:(nonnull GLRouteEnumPointsBlock)block;
Swift
func enumPoints(from startPoint: UInt, with block: @escaping GLRouteEnumPointsBlock)
Parameters
startPoint
The index of the starting point.
block
The enumerator block to call for each point.
-
Calculates number of poins in all legs of route
Declaration
Objective-C
- (NSUInteger)numberOfPoints;
Swift
func numberOfPoints() -> UInt
Return Value
number of poitns in all legs of route
-
Adds a distance and unit description to an instruction.
Declaration
Objective-C
- (NSString *_Nullable)getApproachAlert:(nonnull NSString *)instruction distance:(double)distance;
Swift
func getApproachAlert(_ instruction: String, distance: Double) -> String?
Parameters
instruction
The instruction text.
distance
The distance to include in the new approach alert instruction.
Return Value
An instruction with an approach alert that includes distance.
-
An array containing all the maneuvers in the route.
Declaration
Objective-C
@property (readonly) NSArray<GLRouteManeuver *> *_Nonnull allManeuvers;
Swift
var allManeuvers: [GLRouteManeuver] { get }
-
The language of the instructions in the maneuvers.
Declaration
Objective-C
@property (readonly) NSString *_Nullable language;
Swift
var language: String? { get }
-
The height data for the route.
Declaration
Objective-C
@property (readonly) GLRouteElevation *_Nullable heightData;
Swift
var heightData: GLRouteElevation? { get }
-
Alternative routes, if available.
Declaration
Objective-C
@property (readonly) NSArray<GLRoute *> *_Nullable alternates;
Swift
var alternates: [GLRoute]? { get }
-
Serializes the route settings as a JSON string.
Declaration
Objective-C
- (nonnull NSString *)toJSON;
Swift
func toJSON() -> String
Return Value
A JSON string with the route settings.