android地圖的集成比較簡單。
- 創(chuàng)建一個android應(yīng)用
- 在高德開放平臺創(chuàng)建應(yīng)用
- 集成
創(chuàng)建一個android新項(xiàng)目

image.png
就一個剛創(chuàng)建好的應(yīng)用,啥沒改。
在高德開放平臺創(chuàng)建應(yīng)用
高德開放平臺地址:https://lbs.amap.com/
進(jìn)入控制臺,點(diǎn)擊“創(chuàng)建新應(yīng)用”,創(chuàng)建類型根據(jù)自己APP類型選擇。

image.png
創(chuàng)建完成之后,key都是空的,還需要綁定自己的APP:

image.png
點(diǎn)擊項(xiàng)目條目中的右側(cè)“添加key”也就是“+”號:

image.png
信息填寫完畢直接提交就能生成key。

image.png
集成
集成主要修改兩個文件:
1:AndroidManifest.xml
2:build.gradle
往AndroidManifest.xml中添加權(quán)限以及apikey,apikey必須與平臺的key一致:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hdc.test">
<!--地圖包、搜索包需要的基礎(chǔ)權(quán)限 -->
<!--允許程序打開網(wǎng)絡(luò)套接字-->
<uses-permission android:name="android.permission.INTERNET" />
<!--允許程序設(shè)置內(nèi)置sd卡的寫權(quán)限-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--允許程序獲取網(wǎng)絡(luò)狀態(tài)-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--允許程序訪問WiFi網(wǎng)絡(luò)信息-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!--允許程序讀寫手機(jī)狀態(tài)和身份-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--允許程序訪問CellID或WiFi熱點(diǎn)來獲取粗略的位置-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="624fbeb44e525a70bcaa3756b9a18ae8"/>
</application>
</manifest>
build.gradle中設(shè)置SO庫架構(gòu)以及高德地圖的jar包:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.hdc.test"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//高德地圖配置開始
ndk {
//設(shè)置支持的SO庫架構(gòu)(開發(fā)者可以根據(jù)需要,選擇一個或多個平臺的so)
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86","x86_64"
}
//高德地圖配置結(jié)束
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//高德地圖配置開始
//3D地圖so及jar
compile 'com.amap.api:3dmap:latest.integration'
//定位功能
compile 'com.amap.api:location:latest.integration'
//搜索功能
compile 'com.amap.api:search:latest.integration'
//高德地圖配置結(jié)束
}
官方配置地址:https://lbs.amap.com/api/android-sdk/guide/create-project/android-studio-create-project
也可通過拷貝添加SDK方式進(jìn)行配置。
調(diào)用:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.amap.api.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.amap.api.maps.MapView>
</RelativeLayout>
package com.hdc.test;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
/**
* 這是調(diào)用者
*/
public class MainActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView mapView = (MapView) findViewById(R.id.map);
mapView.onCreate(savedInstanceState);// 此方法必須重寫
AMap aMap = mapView.getMap();
}
}

Screenrecorder-2019-02-13-17-24-39-246.gif
已完成測試!有不對的地方歡迎指出,感恩。