Approximate time: 5-10 mins
Now let's have some fun by adding turn-by-turn navigation to your app!
TGDrivingSimulator.shared.startingCoordinate = CLLocationCoordinate2D(latitude: 34.101558, longitude: -118.340944) // Grauman's Chinese Theatre
TGDrivingSimulator.shared.enabled = true
// Get these coordinates from your app, these are just a sample
let origin = TGWaypoint(coordinate: CLLocationCoordinate2D(latitude: 34.101558, longitude: -118.340944)) // Grauman's Chinese Theatre
let destination = TGWaypoint(coordinate: CLLocationCoordinate2D(latitude: 34.011441, longitude: -118.494932)) // Santa Monica Pier
// Configure turn-by-turn navigation
let config = TGTurnByTurnConfiguration()
config.showsOriginIcon = false
config.originWaypoint = origin
config.destinationWaypoint = destination
config.commencementSpeech = "Let's go!"
config.proceedToRouteSpeech = "Please proceed to the route."
config.arrivalSpeech = "You have arrived."
// Display it
let viewController = TGPreviewViewController.create(with: config).embedInNavigationController()
present(viewController, animated: true, completion: nil)
// If you’d rather skip the preview and jump straight into directions, you can do that:
//let viewController = TGTurnByTurnViewController.create(with: config)
//present(viewController, animated: true, completion: nil)
After you've seen it working at your desk, at some point you'll probably want to take it for a spin in your car. In which case, you'll want to stop using the driving simulator and start using your real location instead.
To do this, simply set
TGDrivingSimulator.shared.enabled = false
.
Then, set the origin waypoint to the user's current location, or use our convenience constructor:
let origin = TGWaypoint.withUserCurrentLocation()
TGDrivingSimulator.sharedDrivingSimulator.startingCoordinate = CLLocationCoordinate2DMake(34.101558, -118.340944); // Grauman's Chinese Theatre
TGDrivingSimulator.sharedDrivingSimulator.enabled = YES;
// Get these coordinates from your app, these are just a sample
TGWaypoint *origin = [TGWaypoint.alloc initWithCoordinate:CLLocationCoordinate2DMake(34.101558, -118.340944)]; // Grauman's Chinese Theatre
TGWaypoint *destination = [TGWaypoint.alloc initWithCoordinate:CLLocationCoordinate2DMake(34.011441, -118.494932)]; // Santa Monica Pier
// Configure turn-by-turn navigation
TGTurnByTurnConfiguration *config = [TGTurnByTurnConfiguration new];
config.showsOriginIcon = NO;
config.originWaypoint = origin;
config.destinationWaypoint = destination;
config.commencementSpeech = @"Let's go!";
config.proceedToRouteSpeech = @"Please proceed to the route.";
config.arrivalSpeech = @"You have arrived.";
// Display it
UINavigationController *viewController = [[TGPreviewViewController createWithConfiguration:config] embedInNavigationController];
[self presentViewController:viewController animated:YES completion:nil];
// If you’d rather skip the preview and jump straight into directions, you can do that:
//TGTurnByTurnViewController *viewController = [TGTurnByTurnViewController createWithConfiguration:config];
//[self presentViewController:viewController animated:YES completion:nil];
After you've seen it working at your desk, at some point you'll probably want to take it for a spin in your car. In which case, you'll want to stop using the driving simulator and start using your real location instead.
To do this, simply set
TGDrivingSimulator.sharedDrivingSimulator.enabled = NO;
.
Then, set the origin waypoint to the user's current location, or use our convenience constructor:
TGWaypoint *origin = [TGWaypoint waypointWithUserCurrentLocation];