MapQuest iOS SDK

iPhones with MapQuest Maps

Getting Started

MapQuest Key

In order to use MapQuest APIs and SDKs you will need a MapQuest Key. We use this key to associate your requests to APIs with your account. You can find your existing Keys or create a new one at Applications page.

Sample Key Page

If you don't have a MapQuest Developer Account you can sign up for one. Sign Up Here.

Xcode and Apple’s iOS SDK

You can get these for free from the Mac App Store. Download Xcode Here

Apple Developer Account (optional)

You can use your personal devices or Xcode’s iOS Simulator for this guide without an Apple Developer Account. If you want to distribute your app to others, you’ll need to sign up and pay for an account. Sign Up Here

Setup Xcode

Project Setup

Open Xcode and go to File ‣ New ‣ Project to create a new project. Go to the iOS Application section and choose the Single View Application template.

Single Page Application

Set Product name to My First MapQuest App. Select Objective-C or Swift (whichever you prefer) as the language and iPhone as the device. For this guide, you’ll be developing an iPhone app. If you plan to support both iPhone and iPad, you can choose Universal as the device.

Application Options

Click Next to create a local folder that Xcode will store all your files in.

Downloading the MapQuest iOS SDK

Manual

Download the zipped SDK that contains the framework and a resource bundle that need to be included in the project

CocoaPods

Use the MapQuest iOS SDK within your own Xcode project using CocoaPods.

You need to include the following in the podfile:

source 'https://github.com/MapQuest/podspecs-ios.git'

pod 'MapQuestMaps'

Using your MapQuest Key in the SDK

To use the MapQuest SDK in your app, you need to place your MapQuest Key inside the app’s Info.plist file:

  1. In the Project navigator (in the left sidebar), find your app’s Info.plist.
  2. Select the “Information Property List” row at the top, and go to Editor ‣ Add Item.
  3. In the new row that is inserted, set the Key to MQApplicationKey and set the Value to your Key.
Info.plist

If you plan on using the traffic feature, you will also need to allow arbitrary loads in your app. You can do this by adding NSAppTransportSecurity to your Info.plist with NSAllowsArbitraryLoads set to true. We are actively working on resolving this requirement. If you are not planning on using traffic, then no further configuration is required.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Adding a map using storyboards

Use the Interface Builder storyboard. Select the existing view from your view controller, then in the Identity inspector tab in the right sidebar, change the class to MQMapView. This adds the MapQuest map into the view controller.

Storyboard

Examples

Basic Map View

iPhone with Map
- (void)viewDidAppear:(BOOL)animated
{
   [super viewDidAppear:animated];
   self.mapView.mapType = MQMapTypeNormal;
}
override func viewDidLoad() {
   super.viewDidLoad()
   mapView?.mapType = .Normal
}

Basic Satellite View

iPhone with Satellite Map
- (void)viewDidAppear:(BOOL)animated
{
   [super viewDidAppear:animated];
   self.mapView.mapType = MQMapTypeSatellite;
}
override func viewDidLoad() {
   super.viewDidLoad()
   mapView?.mapType = .Satellite
}

Set the Map to a Latitude/Longitude

iPhone with centered map
CLLocationCoordinate2D nyc = CLLocationCoordinate2DMake(40.7326808, -73.9843407);
[self.mapView setCenterCoordinate:nyc zoomLevel:11 animated:YES];
let nyc = CLLocationCoordinate2D(latitude: 40.7326808, longitude: -73.9843407)
mapView?.setCenterCoordinate(nyc, zoomLevel: 11, animated: true)

Put a Marker on the Map

iPhone with Map and Marker
MGLPointAnnotation *sanFran = [[MGLPointAnnotation alloc] init];
sanFran.coordinate = CLLocationCoordinate2DMake(37.7749, -122.4194);
sanFran.title = @"San Francisco";
sanFran.subtitle = @"Welcome to San Fran";

[self.mapView addAnnotation:sanFran];
[self.mapView setCenterCoordinate:sanFran.coordinate zoomLevel:10 animated:YES];
let sanFran = MGLPointAnnotation()
sanFran.coordinate = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194)
sanFran.title = "San Francisco"
sanFran.subtitle = "Welcome to San Fran"

mapView?.addAnnotation(sanFran)
mapView?.setCenterCoordinate(sanFran.coordinate, zoomLevel: 10, animated: true)

Put a Polyline on the Map

iPhone with Map and Polyline
CLLocationCoordinate2D coordinates[] = {
    CLLocationCoordinate2DMake(32.7153300, -117.1572600),
    CLLocationCoordinate2DMake(39.7391500, -104.9847000),
    CLLocationCoordinate2DMake(25.7742700, -80.1936600),
    CLLocationCoordinate2DMake(40.7326808, -73.9843407)
};
NSUInteger numberOfCoordinates = sizeof(coordinates) / sizeof(CLLocationCoordinate2D);
MGLPolyline *polyline = [MGLPolyline polylineWithCoordinates:coordinates count:numberOfCoordinates];
[self.mapView addAnnotation:polyline];
[self.mapView showAnnotations:@[polyline] animated:YES];
var coordinates = [
    CLLocationCoordinate2D(latitude: 32.7153300, longitude: -117.1572600),
    CLLocationCoordinate2D(latitude: 39.7391500, longitude: -104.9847000),
    CLLocationCoordinate2D(latitude: 25.7742700, longitude: -80.1936600),
    CLLocationCoordinate2D(latitude: 40.7326808, longitude: -73.9843407)
]

let polyline = MGLPolyline(coordinates: &coordinates, count: UInt(coordinates.count))
mapView?.addAnnotation(polyline)
mapView?.showAnnotations([polyline], animated: true)

Put a Polygon on the Map

iPhone with Map and Polygon
CLLocationCoordinate2D coordinates[] = {
    CLLocationCoordinate2DMake(39.744465080845458,-105.02038957961648),
    CLLocationCoordinate2DMake(39.744460864711129,-105.01981090977684),
    CLLocationCoordinate2DMake(39.744379574636383,-105.01970518778262),
    CLLocationCoordinate2DMake(39.743502042120781,-105.01970874744497),
    CLLocationCoordinate2DMake(39.743419794549339,-105.01977839958302),
    CLLocationCoordinate2DMake(39.74341214360723,-105.02038412442006),
    CLLocationCoordinate2DMake(39.74349726029007,-105.02049233399056),
    CLLocationCoordinate2DMake(39.744393745651706,-105.0204836274754)
};
NSUInteger numberOfCoordinates = sizeof(coordinates) / sizeof(CLLocationCoordinate2D);
MGLPolygon *polygon  = [MGLPolygon polygonWithCoordinates:coordinates count:numberOfCoordinates];
[self.mapView addAnnotation:polygon];
[self.mapView showAnnotations:@[polygon] animated:YES];
var coordinates = [
    CLLocationCoordinate2DMake(39.744465080845458,-105.02038957961648),
    CLLocationCoordinate2DMake(39.744460864711129,-105.01981090977684),
    CLLocationCoordinate2DMake(39.744379574636383,-105.01970518778262),
    CLLocationCoordinate2DMake(39.743502042120781,-105.01970874744497),
    CLLocationCoordinate2DMake(39.743419794549339,-105.01977839958302),
    CLLocationCoordinate2DMake(39.74341214360723,-105.02038412442006),
    CLLocationCoordinate2DMake(39.74349726029007,-105.02049233399056),
    CLLocationCoordinate2DMake(39.744393745651706,-105.0204836274754)
]

let polygon = MGLPolygon(coordinates: &coordinates, count: UInt(coordinates.count))
mapView?.addAnnotation(polygon)
mapView?.showAnnotations([polygon], animated: true)

Use the Users Location

iPhone with Map and Users Location
self.mapView.userTrackingMode = MGLUserTrackingModeFollow;
mapView?.userTrackingMode = .Follow

Add Traffic to a Map

iPhone with Map and Traffic
self.mapView.trafficEnabled = !self.mapView.trafficEnabled;
mapView?.trafficEnabled = true

Night Mode Style

iPhone with Night Mode Map
- (void)viewDidAppear:(BOOL)animated
{
   [super viewDidAppear:animated];
   self.mapView.mapType = MQMapTypeNightMode;
}
override func viewDidLoad() {
   super.viewDidLoad()
   mapView?.mapType = .NightMode
}

Supporting Documentation