Monday 8 December 2008

Exploring MapKit #1

For a recent project I needed the MapView from MapKit, the private Mapping API used by the iPhones on-board map application. This is not sanctioned by Apple in any way, and we are not deploying our app using MapKit to the AppStore - it is for research purposes only.

Gaining access to this API is fairly easy, but does require some steps to accomplish.

  • First, get a copy of the Perl script listed here: [arstechnica.com]. Make sure you update the file paths to the right version of the SDK, i.e. 2.1 to 2.2. By default, the Perl script rips the header files of the private api to: ~/HEADERS
  • In XCODE, add the ~/HEADERS directory to the include path.
  • Import the GMM and MapKit frameworks from the iPhone SDK to your project. As these frameworks are not available for the emulator, you will only be able to run your code using these frameworks directly on the device.
  • To include a MapView, you need to import the following:
    #import < MapKit/MKMapView.h >
  • You may have to remove any imports done in MapView.h, and rename the "anonymousstructXX" declared in the header to some sane datatype, such CGPoint. (Use the name of the function as a context to determine the right data type).
  • Add a MapView to your UIView and assign the UIView as delegate with the following code:
    map = [[MKMapView alloc] initWithFrame: frame];
    [map setDelegate: self];
You can point the MapView to coordinates of your choice with the following selector:

[map goToCenterLongLat:<#(struct CGPoint)fp8#> zoomLevel:<#(float)fp16#> animationType:<#(int)fp20#>]

There are numerous other selectors in the API, and I'll point out interesting ones once I get to know the API better. In future posts I would like to demonstrate how to change the tiling behaviour (caching more tiles) and how to integrate advanced map features, as well as starting a Street View based on the current map coordinates.