Did you ever wonder why Apple didn't provide a way to show directions directly on top of MKMapView and force you to switch to their built-in Maps.app just to guide your users somewhere? We too, that's why we built MTDirectionsKit.
MTDirectionsKit is a full-featured and easy to use solution to show directions in your App, directly on top of MKMapView and works pre-iOS7.
Convinced? Let's get you started.
MTDirectionsKit can use the following three APIs for gathering routing information:
The honest answer: it's not worth the investment anymore. Since Apple previewed iOS 7 at WWDC 2013 sales basically vanished and I couldn't justify my time investment anymore. The MapQuest API changed, there is still no 64 Bit support and the API could need some adjustments to fit iOS7's built-in routing API. The worst I could have done would have been to let MTDirectionsKit die.
By open sourcing it I have high hopes that someone will pick it up and make it up-to-date again. At least I hope that some of you will be able to learn from the code and how to setup an iOS component.
Tell me how you like it, you can find me on Twitter as @myell0w.
MTDirectionsKit is now free to use, if you add a license to your app or to your settings bundle. You can still purchase a non-attribution license, if you don't want to add the license file to your app, or simply if you want to support me.
MTDirectionsKit is very easy to use, here's a sample call:
// MapKit
MTDMapView *_mapView = [[MTDMapView alloc] initWithFrame:frame];
// Google Maps SDK for iOS
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:51.3871 zoom:6];
MTDGSMMapView *_mapView = [MTDGMSMapView mapWithFrame:self.view.bounds camera:camera];
// ...
// setup _mapView
// ...
// configure MTDirectionsKit (optional)
// log more messages
MTDDirectionsSetLogLevel(MTDLogLevelInfo);
// change used API to Google Directions
MTDDirectionsSetActiveAPI(MTDDirectionsAPIGoogle);
// manually change measurement system
// Warning: MTDirectionsKit automatically sets it to the preferred one of the user's device,
// only override if you have a really good reason to
MTDDirectionsSetMeasurementSystem(MTDMeasurementSystemMetric);
// set the delegate of MKMapView. This automatically sets the directionsDelegate, if self
// conforms to the protocol MTDDirectionsDelegate
_mapView.delegate = self;
[_mapView loadDirectionsFrom:CLLocationCoordinate2DMake(51.38713, -1.0316)
to:CLLocationCoordinate2DMake(51.4554, -0.9742)
routeType:MTDDirectionsRouteTypeFastestDriving
zoomToShowDirections:YES];
To see a detailed example on how to use MTDirectionsKit have a look at the provided Demo Application.
CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like MTDirectionsKit in your projects.
platform :ios, '6.0'
pod "MTDirectionsKit", "~> 1.7.0"
There are two ways to integrate MTDirectionsKit into your App:
- Include the binary framework MTDirectionsKit.framework
- Add MTDirectionsKit.xcodeproj as a dependency
The easiest way to integrate MTDirectionsKit is to add the binary framework to your App.
Independent of which way to integrate MTDirectionsKit you choose, you have to add some system frameworks and libraries to your project. For MTDirectionsKit to work you have to add
CoreLocation.framework
MapKit.framework
libxml2.dylib
to your target's linked libraries (found under Build Phases, see pictures below). Moreover open the Build Settings of your project and add -ObjC to the Other Linker Flags section.
If you want to use the built-in images for the textual instructions make sure to alse add MTDirectionsKit.bundle to your projects resources. You can find MTDirectionsKit.bundle under the Resources folder of MTDirectionsKit.
Just drag MTDirectionsKit.framework onto the Frameworks-group of your App, add
#import <MTDirectionsKit/MTDirectionsKit.h>
everywhere you want to use it and you are good to go.
First copy the whole MTDirectionsKit project into your applications root folder and use this project for the following steps:
- Locate the "MTDirectionsKit.xcodeproj" file inside your applications root folder and drag it onto the root of your Xcode project's Frameworks-group
- Add MTDirectionsKit as target dependency of your target under the tab Build Phases
- Drag libMTDirectionsKit.a onto the section 'Link Binary with Libraries' of your target
You are good to go, just
#import <MTDirectionsKit/MTDirectionsKit.h>
everywhere where you want to use it.
If you use the Google Maps SDK version of MTDirectionsKit be sure to check out Google's Guide for integrating their SDK.
Official support is only provided for the Google Maps SDK version included in the MTDirectionsKit distribution bundle, other versions may be unstable or buggy.
MTDirectionsKit needs Xcode ≥ 4.5, iOS Base SDK ≥ 6.0 and Clang LLVM >= 3.1 to compile. It doesn't work with the old LLVM GCC compiler.
MTDirectionsKit works on a deployment target of ≥ iOS 4.3 on armv7 and armv7s and can be used in ARC as well as non-ARC applications.