iOS API Tutorials
Tutorial 3 — Camera Orientation
Adding Track-Up functionality to the GPS code from Tutorial 2
In Tutorial 2 we added code so that the app can respond to GPS coordinates from the device. Here in Tutorial 3 we will add code so that Track-Up functionality is created. The idea behind Track-Up mode is to rotate the map as the vehicle changes direction.
We need to add one new property to ViewController.h:
Modify the didUpdateToLocation function in ViewController.m so that this piece of code is added to the end of the function:
This sets the camera orientation in the mapping engine to match the heading reported by the GPS.
Add this function to ViewController.m:
This function can handle enabling an disabling of the Track-Up functionality.
Add this line to the bottom of the viewDidLoad function in ViewController.m:
Run the app. In the iOS Simulator menu bar, choose the Debug menu and then choose the Location item. Choose one of the options that show motion, like "Freeway Drive" or "City Bicycle Ride". Look in the console window of Xcode and you will see the speed and course changing. The map should pan to the new location so that the new location is centered on the screen and rotate the map to demonstrate Track-Up mode.
If you get lost or wish to save yourself the typing, simply checkout tutorial3 using these commands:
git reset --hard
git checkout tutorial3
Now we would like the add a couple of buttons over the mapping engine to add some basic UI functionality to the app. This is explained Tutorial 4.