Document Maps SDK for Android Get Started

Get Started

This guide provides a quick introduction to adding a map to your Android app using the AMAP Android SDK.

Before You Begin

Before you start, ensure you have the following:

Android Studio — Download and install the latest version from the official Android developer site. Follow the installation instructions for your platform.

Step 1: Obtain an AMAP Key

To use AMAP services, you need to obtain an API key.

Step 2: Create a New Project

Create a new Android project with an Empty Activity template.

1. Launch Android Studio.

- If you see the Welcome to Android Studio dialog, click Start a new Android Studio project.

- Otherwise, go to File > New > New Project.

2. Enter your application name, company domain, and project location. Click Next.

3. Select the form factors your app will run on. For most cases, choose Phone and Tablet. Click Next.

4. In the Add an Activity to Mobile dialog, select Empty Activity. Click Next.

5. Enter the Activity name, layout name, and title. You can use the default values. Click Finish.

Step 3: Download and Install the Map SDK

Download the AMAP Map SDK from the official download page.

For example, version 3.3.3 of the map SDK includes:

AMap3DMap_3.3.3_20160726.jar

- The armeabi folder containing:

libgdinamapv4sdk752.so

libgdinamapv4sdk752ex.so

libtbt3631.so

libwtbt144.so

For detailed installation steps, refer to the Android Studio JAR and SO file setup guide.

Step 4: Configure Your Project

4.1 Configure AndroidManifest.xml

Add your AMAP key in the <application> tag:

<meta-data
    android:name="com.amap.api.v2.apikey"
    android:value="Your AMAP Key"/>

Add the required permissions for the Map SDK:

<!-- Required: Allow internet access -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Allow access to approximate location; required if using GPS for the blue dot location feature -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<!-- Allow access to network state for network-based location; required if GPS is unavailable but the blue dot location feature is still needed -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Allow access to Wi-Fi network information for network-based location; required if GPS is unavailable but the blue dot location feature is still needed -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<!-- Allow monitoring Wi-Fi state changes for network-based location; required if GPS is unavailable but the blue dot location feature is still needed -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

<!-- Allow writing to device cache for troubleshooting purposes -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

Add the required permissions for the Search SDK:

<!-- Required: Allow internet access -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Allow access to network state -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Allow access to Wi-Fi network information -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<!-- Allow writing to device cache for troubleshooting purposes -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

4.2 Configure the Layout XML

Add the MapView control to your layout file:

<com.amap.api.maps.MapView
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</com.amap.api.maps.MapView>

4.3 Display the Map

In your Activity, initialize the map in the onCreate method:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.basicmap_activity); // Set the corresponding XML layout file
    
    MapView mapView = (MapView) findViewById(R.id.map);
    mapView.onCreate(savedInstanceState); // This method must be overridden
    AMap aMap = mapView.getMap();
    
}

Step 5: Connect an Android Device

To test your app on a real device:

1. Enable Developer options and USB debugging on your Android device. Follow the official instructions.

2. Connect your device to your computer via USB.

Alternatively, you can use the Android Emulator:

- Use the Android Virtual Device (AVD) Manager to create and configure one or more virtual devices.

- Build and run your app on the emulator.

Step 6: Build and Run Your App

1. In Android Studio, click the Run button (or the play icon) in the toolbar.

2. When prompted to select a device:

- Choose your connected Android device, or

- Select Launch emulator and pick a previously configured virtual device.

3. Click OK. Android Studio uses Gradle to build your app and deploy it to the selected device or emulator.

The app may take a few minutes to launch. You should see a map displayed in your app.

Note: If the map does not appear, check that your device has an active internet connection. If the map appears but features like POI search or route planning do not work, verify that you have added your AMAP key correctly in AndroidManifest.xml.