Inspect Route Element for iOS v3
In this tutorial we will request a route, list the route parts and render these on a Google Map. A MapsIndoors route is made of one or more legs, each containing one or more steps.
We will start by making the controller that renders the route from the input of a route, a leg index and optionally a step index. Start by creating a UIViewController implementation that conforms to MPDirectionsRendererDelegate
class ShowRouteOnMapController: UIViewController, MPDirectionsRendererDelegate Setup member variables for ShowRouteOnMapController:
An instance of type
GMSMapViewAn instance of type
MPMapControlAn instance of type
MPRoute(the route object)A leg index
A step index
var map: GMSMapView? = nil
var mapControl: MPMapControl? = nil
var route:MPRoute? = nil
var leg:Int = -1
var step:Int = -1Create an initializer for your input parameters
convenience init(_ route:MPRoute, _ leg:Int, _ step:Int) {
self.init(nibName:nil, bundle:nil)
self.route = route
self.leg = leg
self.step = step
}Setup the Google map and your MPMapControl instance
Inside viewDidAppear, setup a directions renderer and assign the Google map, route object and leg/step indices. Eventually, call the animate method to make it animate from the start to end of the leg/step
In the floorDidChange delegate method change the floor on your MPMapControl instance
See the sample in ShowRouteOnMapController.swift
Create the Controller That Requests the Route, and List the Route in a Table
A MapsIndoors route is made of one or more legs, each containing one or more steps. Start by creating a UIViewController implementation
Add a MPRoute property to the class
Inside viewDidLoad, setup a directions service, call the directions service and save the route result to your MPRoute property
Override numberOfRowsInSection to return the number of steps in the current leg plus the leg itself
Override numberOfSections to return the number of legs
Override titleForHeaderInSection to return the leg index
Override tableView:cellForRowAt to return leg index and step index if applicable
Override tableView:didSelectRowAt to push a new view controller
Last updated
Was this helpful?