Map Display
The key class for Map Display is AMAP. In your application, AMAP is a map object. The AMAP map is displayed through the mapfragment or mapview container class.
AMAP automatically handles the following operations:
1. Connect to AMAP
2. Download map data
3. display a map on the device Screen
4. display various controls, such as zoom controls
5. Supports various gestures, such as pan and zoom gestures.
The following uses mapview as an example to describe how to display a map:
Mapview is a subclass of the android View class. It helps you place maps in the android view. It is a basic building class for applications and widgets. As a map container, mapview displays a map through an AMAP object. To use the mapview class, you must Reload all methods of the activity lifecycle, including oncreate (), ondestroy (), onresume (), onpause (), and onsaveinstancestate ().
The map display effect is as follows:
The sample code is as follows (For details, refer to the example project "Basic Map" case ):
When a 3D map is displayed, the layout file (RES/layout/basicmap_activity.xml ):
<? XML version = "1.0" encoding = "UTF-8"?> <! -- Introduce the layout file --> <COM. AMAP. API. maps. mapview xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Id = "@ + ID/Map" Android: layout_width = "match_parent" Android: layout_height = "match_parent"/>
Layout file (RES/layout/basicmap_activity.xml) when a 2D map is displayed ):
<? XML version = "1.0" encoding = "UTF-8"?>! -- Introduce the layout file --> <COM. AMAP. API. maps2d. mapview xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Id = "@ + ID/Map" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"/>
Program code (COM. amapv2.apis. Basic. basicmapactivity. Java ):
| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
/** * The amapv2 map describes how to use mapview to display a map. */public class BasicMapActivity extendsActivity { privateMapView mapView; privateAMap aMap; @Override protectedvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // R needs to reference the package import com. amapv2.apis. R; setContentView(R.layout.basicmap_activity); mapView = (MapView) findViewById(R.id.map); mapView.onCreate(savedInstanceState);// Required init(); } /** * Initialize an AMAP object */ privatevoid init() { if(aMap == null) { aMap = mapView.getMap(); } } /** * The method must be overwritten. */ @Override protectedvoid onResume() { super.onResume(); mapView.onResume(); } /** * The method must be overwritten. */ @Override protectedvoid onPause() { super.onPause(); mapView.onPause(); } /** * The method must be overwritten. */ @Override protectedvoid onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mapView.onSaveInstanceState(outState); } /** * The method must be overwritten. */ @Override protectedvoid onDestroy() { super.onDestroy(); mapView.onDestroy(); }} |
Rotate a map with a certain pixel on the screen (3D)
AMAP Android SDK allows you to rotate a map at a certain pixel on the screen. The specific implementation is to use the setpointtocenter () method of the AMAP class to set a screen pixel to the map center point, and then use the changebearing (float bearing) method of the cameraupdate class to change the map rotation angle.
For example, AMAP. setpointtocenter (, 0) sets the screen pixel (, 0) as the map center point. cameraupdate. changebearing (90) changes the map rotation angle, which means that the map is rotated by the screen pixel.
Set the line surface above or below the map basemap text (3D)
AMAP Android SDK allows you to set the overlay of line and surface to the top or bottom of the map text.
The specific implementation is to use the setmaptextzindex () method of the AMAP class to set the z-axis index of the map basemap text. By default, the Z-axis index of the map text and the cover is 0. At this time, the map text is below the cover, if AMAP is used. setmaptextzindex (2) allows you to set the basemap text on the added cover.
[AMAP Development] --- Map Display