Complete steps for IOS to call Gaode map SDK

Time:2022-1-14

preparation:

Install cocoapods and download the SDK in the same way as downloading third-party libraries

The method is as follows:

(1) Open the terminal and enter the CD file path into the created project file

(2) Inputpod initCreate a podfile file for the project

(3) Add in podfile filepod 'AMap3DMap'orpod 'AMap2DMap'

Among them, 3D is 3D map and 2D is 2D map. Select one of them to add. If you select all, there will be a conflict, resulting in the failure of SDK installation

(4) Enter pod install to download the SDK (if the downloaded SDK is not the latest version, you can enter it)Update with pod repo update)After downloading, click Xcworkspace file enters the project to write code. In addition, you need to register as a personal developer of Gaode map and go to“Gaode open platform console”Apply for IOS key. The IOS key needs to be used in actual project writing

The key application method is as follows:

Sign in or register

1. If you have not already registered, please click here to complete the registration.

2. If you have already registered, please log in and apply for key. The entry of application and registration is as follows:

请添加图片描述

Create application

Enter “console – Application Management – create new application” and click here to enter.

请添加图片描述

Apply to add a key for this application

1. Click “+” on the left to add a key.

请添加图片描述

2. Fill in the necessary fields. At this time, you need to select the correct key type.

请添加图片描述

Select the IOS platform in the figure above. After selection, you also need to fill in the security code bundle ID:, and the acquisition of the security code is shown in the figure below:

请添加图片描述

After filling in everything, we can get the key we need

Next, go to the internal settings of the project:

1. In order to enhance data access security, ios9 changes all HTTP requests to HTTPS. In order to normally use the map SDK in ios9, the following configuration needs to be made in “info. Plist”, otherwise the use of the SDK will be affected (see the figure below):

We need to create allow aircraft loads under app transport security settings and set its type to Boolean value to yes; If there is no app transport security settings, you need to create one

2. Configure Gaode key to appdelegate M file:

#import <AMapFoundationKit/AMapFoundationKit.h>
//You need to introduce amapfoundation kit H header file
……

 (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
	//Modify the key part below to the key just obtained;
    [AMapServices sharedServices]. Apikey = @ "your key";
     
    ……
}

3. Method of loading map:

In viewcontroller Map initialization is carried out in the corresponding method of m file. The initialization steps are as follows:

(1) import MAMapKit. H) header file;

(2) Construct mamapview object;

(3) Add mamapview to the subview.

For 3D vector maps, add code to the viewdidload method:

#import <MAMapKit/MAMapKit.h>

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

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

Important points:

After realizing the above operations, we still can’t successfully load the map. At this time, the operation will promptGaode map SDK privacy complianceRelated problems. This is because laws and regulations must pass this test for the content required by the app, otherwise the map view cannot be displayed. However, don’t panic. See the following:

Before constructing mamapview (maofflinemap, maofflinemapviewcontroller, matracemanager, etc.), compliance check must be carried out. Before setting the interface, ensure the compliance of privacy policy. The check interface is as follows:


[MAMapView updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];
[MAMapView updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];

The view of the map can be loaded successfully before adding the above two lines of interface code to the code for loading the map view.

That is, the viewcontroller The code in M is written as follows:

#import <MAMapKit/MAMapKit.h>

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

	//Add privacy compliance interface code
	[MAMapView updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];
	[MAMapView updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];

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

At this point, all our processes are over, and the actual operation results are as follows:

请添加图片描述

You can see that the map view has been displayed on our mobile phone.

summary

This is the end of this article about IOS calling the Gaode map SDK. For more information about IOS calling the Gaode map SDK, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!

Recommended Today

IOS overall framework and class inheritance framework diagram

I. overall framework In the process of IOS development, understanding and learning the overall framework of IOS is an essential link. Today, let’s have a good understanding of the overall framework of IOS. First, post a framework introduction about IOS:Overview of IOS system framework。 We usually call the IOS framework cocoa touch framework. Cocoa touch […]