开发人员控制台
感谢您的访问。此页面目前仅提供英语版本。我们正在开发中文版本。谢谢您的理解。

Get Started with the Amazon Maps API (v2.5)

The following steps show you how to get started with the Amazon Maps API.

Step 1: Set Up Your Development Environment

Install and configure Android Studio on your computer. If you already have it installed, update to the latest version (4.x).

Android Studio isn't required, but if you're using another tool, make sure you have the Android SDK installed and other system requirements necessary for Android development. Also note that the instructions in this documentation will assume you're using Android Studio.

Step 2: Set Up a Fire Tablet for Testing

Follow the steps described in Connect to Fire Tablet through adb to connect your Fire tablet to your computer.

Step 3: Download the Amazon Maps SDK Support Library

To use the Amazon Maps SDK in your project, you must download the SDK and add it to your project. The library is a Gradle-compatible project. To get the Maps SDK, go to SDK Downloads, download the Amazon Maps SDK version 2.5, and extract the files. For convenience, you can also download the SDK here:

Step 4: Add the AAR File to Your Project

You add the AAR file (amazon-maps-api-v2.aar) to your Android project similar to how you would add other libraries to an Android project — by adding the AAR file into a libs folder.

  1. In Android Studio, switch to the Project view.
  2. Create a directory called libs at the root-level of your project.
  3. Copy and paste the amazon-maps-api-v2.aar file into this libs directory.
  4. In your app's build.gradle file, reference the AAR file in dependencies:

    dependencies {
    implementation(name:'amazon-maps-api-v2', ext:'aar')
    }
    
  5. In the same build.gradle file, add the following in repositories:

    repositories {
      google()
      jcenter()
      mavenLocal()
      flatDir {
          dirs 'libs'
      }
    }
    

Step 5: Configure Your Android Manifest

To use Amazon Maps API features, you must update app permissions listed in the AndroidManifest.xml file. At a minimum, you need the following permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Step 6: Verify Amazon Maps Availability on Device

To ensure a good user experience, your app should check for the presence of the Amazon Maps API on the Fire tablet and adjust accordingly if it is not available.

To check for Amazon Maps, call AmazonMapsRuntimeUtil.isAmazonMapsRuntimeAvailable(). This method returns a result code as an int. Use the constants provided in the ConnectionResult object to determine the result. If Amazon Maps is present, it returns ConnectionResult.SUCCESS.

For example, the following method returns a boolean indicating whether the Amazon Maps API is available:

import com.amazon.geo.mapsv2.util.AmazonMapsRuntimeUtil;
import com.amazon.geo.mapsv2.util.ConnectionResult;

...

private boolean checkForAmazonMaps() {
    // Check for the presence of Amazon Maps on the device

    return AmazonMapsRuntimeUtil
        .isAmazonMapsRuntimeAvailable(this) == ConnectionResult.SUCCESS;
}

The following example shows an onCreate method for an Activity that writes a message to the log if the Amazon Maps API is not available on the device:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (checkForAmazonMaps()) {
        // Maps should be available. Code
        // to get a reference to the map and proceed
        // normally goes here...
    }
    else {
        // Maps is not available. Get the exact result
        // code and write it in a log message
        int cr = AmazonMapsRuntimeUtil.isAmazonMapsRuntimeAvailable(this);
        String msg = getString(R.string.no_maps)
            + " ConnectionResult = " + cr ;

        Log.w(TAG, msg);
    }
}

For an example of displaying an error dialog when the Amazon Maps API is not available on the device, see the CapitolHillCoffee sample app.

Full MainActivity.java Example

Here is an example MainActivity for app com.mytest.maps:

package com.mytest.maps;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.amazon.geo.mapsv2.util.AmazonMapsRuntimeUtil;
import com.amazon.geo.mapsv2.util.ConnectionResult;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (checkForAmazonMaps()) {
            // Maps should be available. Code
            // to get a reference to the map and proceed
            // normally goes here...
        }
        else {
            // Maps is not available. Get the exact result
            // code and write it in a log message
            int cr = AmazonMapsRuntimeUtil.isAmazonMapsRuntimeAvailable(this);
            String msg = " ConnectionResult = " + cr ;

        }
    }

    private boolean checkForAmazonMaps() {
        // Check for the presence of Amazon Maps on the device

        return AmazonMapsRuntimeUtil
                .isAmazonMapsRuntimeAvailable(this) == ConnectionResult.SUCCESS;
    }
}

Step 7: Retrieve your App's MD5 Signature from Android Studio

Every app must have its own registration. Debug and release builds require separate registration. To load map tiles during testing, you must register the debug build of your app. Registration for the release build is a separate process and occurs automatically when you submit your app, if you have already created a debug registration. With your registration request, you must provide the MD5 debug fingerprint.

To get your MD5 Signature:

  1. Open your project in Android Studio.
  2. Click the Gradle tab in the top-right corner.
  3. Expand your app's entry, then expand Tasks, then android, and double click on signingReport.

    After a few seconds, Android Studio generates a report in the status area at the bottom, where you will see MD5, SHA1, and SHA-256 info. Copy the MD5 value and store this info for future reference.

If you aren't using Android Studio, you can extract the MD5 using the keytool utility from the JDK.

Step 8: Add Your App in the Developer Console

If you haven't yet added your app in the Developer Console, see Submitting Apps to the Amazon Appstore.

Step 9: Submit Your Debug Registration Request

To submit a debug registration request for apps that use the Amazon Maps API:

  1. On the developer portal, open the list of your apps.
  2. Click the app that you want to register. (If your app is not listed, first add the app to the portal.)
  3. Click App Services in the left sidebar.
  4. Click Maps.
  5. Click Add a Debug Registration.
  6. In the Package name box, enter the package name for your app.
  7. In the Developer signature box, enter the MD5 fingerprint of the debug certificate that you obtained earlier.
  8. Click Save.

It takes time to propagate the registration to your device. After clicking Submit, allow one hour before testing the app that you registered. If a recently registered app does not show map tiles, you might need to allow more time for registration to take effect.

Step 10: Load Your App on a Device for Testing

Once you have registered your app, connect your device to a development computer for testing and debugging, and build your app. For information about using ADB, see Connect to Fire Tablet through ADB.

Next Step

See Using the Amazon Maps Sample App (v2.5).