Initialization & Compliance
Add the AMAP Key
To ensure the AMAP Android SDK functions correctly, you must apply for an AMAP Key and configure it in your project.
Add the following code to your project's AndroidManifest.xml file:
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="Your AMAP Key"/>
……
</application>Configure Permissions
Configure the required permissions in AndroidManifest.xml.
Map SDK
<!-- Required: Allow network access -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required for GPS-based location (blue dot feature) -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Required for network-based location when GPS is unavailable -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Required for network-based location when GPS is unavailable -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Required for network-based location when GPS is unavailable -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- Optional: Write device cache for troubleshooting -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />Search SDK
<!-- Required: Allow network access -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allow network state access -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Allow WiFi network information access -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Optional: Write device cache for troubleshooting -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />Region & Language Settings
Map SDK
/**
* Returns whether the current environment is outside of mainland China.
*
* @return true if the current environment is overseas, false otherwise
*/
public static boolean isOverSea() {}
/**
* Sets the country or region code to determine which service node to use.
*
* @param countryCode The country or region code (e.g., "US", "GB", "AE")
*/
public static void updateCountryCode(String countryCode) {}
/**
* Sets the region language type.
*
* @param type The language type value. See the language type table for supported values.
*/
public static void initRegionLanguageType(int type) {}
/**
* Returns the current region language type.
*
* @return The current language type value
*/
public static int getRegionLanguageType() {}
/**
* Sets the current coordinates for multi-language region detection.
*
* @param latLng The current location as a LatLng object
*/
public static void setCurrentLocation(LatLng latLng) {}
/**
* Returns the currently configured location for multi-language support.
*
* @return The current location as a LatLng object
*/
public static LatLng getRegionLocation() {}
Search SDK
/**
* Sets the language for search, geocoding, reverse geocoding, and input tips.
* Only Chinese and English are supported in mainland China.
*
* The following 22 language types are supported:
*
* Language Code Language
* zh-Hans Chinese (Simplified)
* zh-Hant-HK Chinese (Traditional, HK)
* en English
* es Spanish
* pt Portuguese
* fr French
* de German
* th Thai
* ja Japanese
* ko Korean
* ar Arabic
* tr Turkish
* he Hebrew
* it Italian
* ru Russian
* ms Malay
* id Indonesian
* vi Vietnamese
* pl Polish
* cs Czech
* uk Ukrainian
* az Azerbaijani
*
* @param language The language code. See {@link ServiceSettings#ENGLISH} or {@link ServiceSettings#CHINESE}
* @since V2.5.0
*/
public void setLanguage(String language) {}
/**
* Returns the current language setting.
*
* @return The current language code
*/
public String getLanguage() {}
Base SDK
/**
* The region language type. Defaults to Chinese (Simplified).
*/
private static int sRegionLanguageType = AMapLangType.LANG_TYPE_ZH;
/**
* Sets the region language type.
*
* @param type The language type value:
* 0 Chinese (Simplified)
* 1 Chinese (Traditional, HK)
* 2 English
* 3 Spanish
* 4 Portuguese
* 5 French
* 6 German
* 7 Thai
* 8 Japanese
* 9 Korean
* 10 Arabic
* 11 Turkish
* 12 Hebrew
* 13 Italian
* 14 Russian
* 15 Malay
* 16 Indonesian
* 17 Vietnamese
* 18 Polish
* 19 Czech
* 20 Ukrainian
* 21 Azerbaijani
* See {@link AMapLangType}
*/
public static void initRegionLanguageType(int type) {
AppInfo.sRegionLanguageType = type;
}
/**
* Returns the current region language type.
*
* @return The current language type value
*/
public static int getRegionLanguageType() {
return AppInfo.sRegionLanguageType;
}
/*
* The country or region code used to identify the user's location.
* Defaults to an empty string.
*/
private static String mCountryCode = "";
/**
* Sets the country or region code used to identify the user's location.
* Has no effect if the country code has already been locked.
*
* @param countryCode The country or region code. Defaults to an empty string if null is passed.
*/
public static void setCountryCode(String countryCode) {
if (sIsCountryCodeLocked) {
return;
}
mCountryCode = countryCode == null ? "" : countryCode;
}
/**
* Returns the currently configured country or region code.
*
* @return The current country or region code
*/
public static String getCountryCode() {
return mCountryCode;
}
Privacy Compliance
Map
1. Privacy compliance API description:
/**
* Update the privacy compliance status. Must be called before initializing the map.
* @param context The application context.
* @param isContains Whether the privacy policy includes AMap's privacy policy. true: yes.
* @param isShow Whether the privacy policy is displayed to the user. true: yes.
* @since 8.1.0
*/
public static void updatePrivacyShow(Context context, boolean isContains, boolean isShow);/**
* Update the privacy agreement status. Must be called before initializing the map.
* @param context The application context.
* @param isAgree Whether the user has agreed to the privacy policy. true: user agreed.
* @since 8.1.0
*/
public static void updatePrivacyAgree(Context context, boolean isAgree);2. Perform privacy compliance check before constructing MapView (applies to OfflineMapManager, LBSTraceClient, etc.). Ensure privacy compliance before calling the setup API:
MapsInitializer.updatePrivacyShow(context, true, true);
MapsInitializer.updatePrivacyAgree(context, true);3. Catch exceptions when constructing OfflineMapManager (applies to LBSTraceClient as well). Example:
try {
mOfflineMapManager = new OfflineMapManager(this, this);
} catch (Exception e) {
// Handle exception
}4. Perform null-pointer check before using mOfflineMapManager:
if (mOfflineMapManager != null) {
// TODO: Use mOfflineMapManager
}5. MapView does not require exception handling. However, if privacy compliance fails, the map will display as a blank screen.
Search
1. Privacy compliance API description:
/**
* Update the privacy compliance status. Must be called before initializing the search.
* @param context The application context.
* @param isContains Whether the privacy policy includes AMap's privacy policy. true: yes.
* @param isShow Whether the privacy policy is displayed to the user. true: yes.
* @since 8.1.0
*/
public static void updatePrivacyShow(Context context, boolean isContains, boolean isShow);/**
* Update the privacy agreement status. Must be called before initializing the search.
* @param context The application context.
* @param isAgree Whether the user has agreed to the privacy policy. true: user agreed.
* @since 8.1.0
*/
public static void updatePrivacyAgree(Context context, boolean isAgree);2. Perform privacy compliance check before constructing PoiSearch (applies to RouteSearch, WeatherSearch, etc.). Ensure privacy compliance before calling the setup API:
MapsInitializer.updatePrivacyShow(context,true,true);
MapsInitializer.updatePrivacyAgree(context,true);3. Catch exceptions when constructing PoiSearch. Example:
try {
mOfflineMapManager = new OfflineMapManager(this, this);
}catch (Exception e){
}4. Perform null-pointer check before using mPoiSearch:
if (mOfflineMapManager != null){
// TODO
}Personal and Device Information Collection Settings
/**
* Configure whether the base SDK is allowed to collect personal and device information.
* @param collectEnable true: collection allowed, false: collection not allowed
*/
AMapUtilCoreApi.setCollectInfoEnable(boolean collectEnable);Code Obfuscation
When generating an APK with code obfuscation, add the following configuration. If warnings are reported, add a -dontwarn statement for the corresponding package.
# 3D Map SDK (Before V5.0.0)
-keep class com.amap.api.maps.**{*;}
-keep class com.autonavi.amap.mapcore.*{*;}
-keep class com.amap.api.trace.**{*;}
# 3D Map SDK (V5.0.0 and Later)
-keep class com.amap.api.maps.**{*;}
-keep class com.autonavi.**{*;}
-keep class com.amap.api.trace.**{*;}
# Location
-keep class com.amap.api.location.**{*;}
-keep class com.amap.api.fence.**{*;}
-keep class com.autonavi.aps.amapapi.model.**{*;}
# Search
-keep class com.amap.api.services.**{*;}
# Navigation
-keep class com.amap.api.navi.**{*;}
-keep class com.autonavi.**{*;}SO File Instructions
The core functionality of the Map SDK and Navigation SDK depends on SO libraries. When using the SDK and adding SO files to your project, please note the following:
Ensure the Correct SO Library Files Are Added
What are the correct SO files?
When a new version of the SDK is officially released, both the JAR files and SO files are updated simultaneously. You must update all these files in your project without omission. Refer to the Eclipse or Android Studio project configuration guides for the correct addition method.
Ensure SO Library Files Match the Platform
What does matching SO files to the platform mean?
arm and x86 represent two different CPU architectures. Different architectures require different SO files. Using the wrong SO file will prevent the SDK from functioning correctly.
The simplest solution is to keep only the armeabi folder in the libs or jnilibs directory.
Compatibility
The SDK supports Android 4.0 (API level 14) and above.