android: map of gaud

Keywords: Android Amap Gradle SDK

Divided into map, location and search (I haven't done navigation yet)

gradle integration is recommended

Add dependency

Add jcenter's warehouse address under the project/build.gradle file

allprojects {
    repositories {
        jcenter() // Or Maven central ()

Add dependency under app/build.gradle

android {
    defaultConfig {
        ndk {
            //Set the supported so Library Architecture (developers can select one or more platforms' so as required)
            abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86","x86_64"

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //3D map so and jar
    compile 'com.amap.api:3dmap:latest.integration'
    //Positioning function
    compile 'com.amap.api:location:latest.integration'
    //Search function
    compile 'com.amap.api:search:latest.integration'

navi navigation SDK later than 5.0.0 includes the 3D map SDK, so please do not introduce map3d and navi SDK at the same time.

add permission

Add permissions under the AndroidManifest.xml file

 <! -- allow programs to open network sockets -- >
<uses-permission android:name="android.permission.INTERNET" />
<! -- allow program to set write permission of bui lt-in sd card -- >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   
<! -- allow programs to get network status -- >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<! -- allow programs to access WiFi network information -- >
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
<! -- allow programs to read and write mobile phone status and identity -- >
<uses-permission android:name="android.permission.READ_PHONE_STATE" />     
<! -- allow programs to access CellID or WiFi hotspot to get rough location -- >
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 

Add GoldKey

How to get key? Here - > Click me to view the method to obtain the necessary data SHA1 and package name for Key registration

It is suggested to set the key in debug and release state at the same time, so that the App can also use the function of Gaud map in debug mode
Set two kinds of key s under app/build.gradle

  android {
       buildTypes {
            debug {
              manifestPlacesholders = [
                      //The left key map? API? Key is a custom name, and the right debug key value is the key value under the debug you applied for
                    "MAP_API_KEY" : "debug-key-value"
            manifestPlacesholders = [
                      //The key map API key on the left should be consistent with that under debug. The release key value on the right is the key value under the release you applied for
                    "MAP_API_KEY" : "release-key-value"

Add key to Android manifest.xml

            //To be consistent with the settings in the app/build.gradle file

Use map

Map MapView in layout

 // R.layout.activity_your_activity




Manage map lifecycle (very important), take Activity as an example

 public class YourActivity extends AppcompatActivity{

     MapView mMapView = null;
  protected void onCreate(Bundle savedInstanceState) {
    //Get map control reference
    mMapView = (MapView) findViewById(;
    //When the activity executes onCreate, execute mMapView.onCreate(savedInstanceState) to create the map
  protected void onDestroy() {
    //When the activity executes onDestroy, execute mMapView.onDestroy() to destroy the map
 protected void onResume() {
    //Execute mMapView.onResume() when the activity executes onResume() to redraw the loading map
 protected void onPause() {
    //Execute mMapView.onPause() when activity executes onPause to pause map drawing
 protected void onSaveInstanceState(Bundle outState) {
    //When the activity executes onSaveInstanceState, execute mMapView.onSaveInstanceState (outState) to save the current state of the map


Construct an AMap object

  if(mAMap == null){
   mAMap = mapView.getMap();

Initialize map related properties

  • Map zoom level
mAMap.animateCamera(CameraUpdateFactory.zoomTo(float zoomLevel));

Show anchor blue dots

To be continued

Posted by Operandi on Wed, 04 Dec 2019 09:03:05 -0800