Get Navigation in your App

Approximate time: 5-10 mins

Now let's have some fun by adding turn-by-turn navigation to your app!

  1. Use the driving simulator so you can try this from the comfort of your desk:
    TGDrivingSimulator.shared.startingCoordinate = CLLocationCoordinate2D(latitude: 34.101558, longitude: -118.340944) // Grauman's Chinese Theatre
    TGDrivingSimulator.shared.enabled = true
  2. Now let's create the view controller and set a few attributes:
    // 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)
  3. Voila! You now have turn-by-turn navigation in your app!
  4. Ready to try it in the real world?

    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()
  1. Use the driving simulator so you can try this from the comfort of your desk:
    TGDrivingSimulator.sharedDrivingSimulator.startingCoordinate = CLLocationCoordinate2DMake(34.101558, -118.340944); // Grauman's Chinese Theatre
    TGDrivingSimulator.sharedDrivingSimulator.enabled = YES;
  2. Now let's create the view controller and set a few attributes:
    // 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];
  3. Voila! You now have turn-by-turn navigation in your app!
  4. Ready to try it in the real world?

    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];
Expected Output
TallyGo