Document Maps SDK for iOS Get Started

Get Started

This guide walks you through the steps required to set up the AMAP SDK for iOS in your development environment.

Step 1: Get the Latest Version of Xcode

To develop projects with the AMAP SDK for iOS, you need Xcode version 8.0 or later. Download it from the Apple Developer website.

Step 2: Install CocoaPods

The AMAP iOS SDK is distributed as CocoaPods pods. CocoaPods is an open-source dependency manager for Swift and Objective-C Cocoa projects.

If you haven't installed CocoaPods yet, run the following command in your terminal on macOS:

$ sudo gem install cocoapods

For more information, see the CocoaPods Getting Started guide.

Step 3: Install the SDK Using CocoaPods

Create a Podfile for the AMAP iOS Map SDK and use it to install the SDK.

1. Create a Podfile

Create a file named Podfile in the same directory as your project file (.xcodeproj). If you haven't created an Xcode project yet, create one now and save it to your local machine. If this is your first iOS project, create a Single View Application.

$ touch Podfile

2. Edit the Podfile

Add the following content to your Podfile:

platform :ios, '7.0' # Target iOS version
target 'YourProjectTarget' do
  pod 'AMap3DMap'  # 3D Map SDK
  #pod 'AMap2DMap' # 2D Map SDK (cannot be used together with 3D)
  pod 'AMapSearch' # Search functionality
end

Note: Using any SDK automatically imports the Foundation SDK. For details about submitting your app to the App Store, see the Foundation SDK introduction.

3. Run pod install

Run the following command to install the SDK:

$ pod install --repo-update

For version 1.1.0 and later, running pod install does not automatically update the local repo. If you are not getting the latest version, use pod install --repo-update or run pod repo update first.

4. Update the SDK

If the installed SDK is not the latest version, run the following command to update:

$ pod repo update

5. Restart Xcode

Close Xcode, then open (double-click) your project's .xcworkspace file to launch Xcode. From this point forward, you must use the .xcworkspace file to open your project.

Step 4: Get an AMAP Key

Go to the AMAP Platform Console to apply for an iOS Key.

Step 5: Hello AMAP

1. Configure Info.plist

iOS 9 enforces App Transport Security (ATS), which requires all HTTP requests to use HTTPS. To use the Map SDK on iOS 9 and later, add the following configuration to your Info.plist file. Without this, the SDK may not function correctly.

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

2. Configure the AMAP Key in AppDelegate.m

Add the AMAP Key you obtained in the previous step to your code. This is required for the map to function correctly.

#import <AMapFoundationKit/AMapFoundationKit.h>
// Import the AMapFoundationKit header file
...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [AMapServices sharedServices].apiKey = @"Your Key";
    ...
}

3. Load the Map

Initialize the map in your ViewController.m file. Follow these steps:

1. Import the MAMapKit.h header file.

2. Create a MAMapView object.

3. Add the MAMapView to the view hierarchy.

For the 3D vector map, add the following code in the viewDidLoad method:

Objective-C:

#import <MAMapKit/MAMapKit.h>

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    /// Initialize the map
    MAMapView *_mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
    
    /// Add the map to the view
    [self.view addSubview:_mapView];
}

Step 6: Connect an iOS Device

The simplest way to test your app on a real device is to connect an iOS device to your computer. On your device, trust your developer certificate and enable location services.

Alternatively, you can use the iOS Simulator included with Xcode. Select a simulator from the scheme menu to build and run your app.

Step 7: Build and Run Your App

In Xcode, select Product > Run (or click the Run button) to build and run your app.

You should see a map displayed in your project. If the map does not appear, check your internet connection. If the map appears but POI search or route planning features do not work, verify that you have added your AMAP Key correctly.

What's Next

You may want to explore sample code. For more information about navigation, see the Developer Guide.