Recently in doing projects to use the map, looked at the map of the gold of the API, and finally decided to use a gold map, and usually different, the map is to embed in the fragment, the study of the online code, and finally realized. Here's how to implement the 2D map.
1. First go to the map website of high Germany to register key, address is http://lbs.amap.com/api/android-sdk/summary/;
2. Download the required SDK according to the instructions.
3. Configuration Engineering
(1) Add key
Add a key to the project's "Androidmanifest.xml" file in the following code.
(1) Add permissions
<pre><code><uses-permission android:name= " Android.permission.INTERNET " /> <uses-permission android:name=" android.permission.WRITE_ External_storage " /> <uses-permission android:name=" Android.permission.ACCESS_COARSE_LOCATION " /> <uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE" /> < Uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name= "Android.permission.READ_PHONE_STATE" /> <uses-permission android:name= " Android.permission.CHANGE_WIFI_STATE " /> <uses-permission android:name=" Android.permission.ACCESS_WIFI_STATE " /> <uses-permission android:name=" Android.permission.CHANGE_CONFIGURATION " /> <uses-permission android:name=" Android.permission.WRITE_SETTINGS "&NBSP;/></CODE></PRE>
4. layout file
<com.amap.api.maps2d.mapview
android:id= "@+id/map"
android:layout_width= "Match_parent"
android: layout_height= "Match_parent"/>
5. To achieve
public class fragmentmap extends fragment{ private
static FragmentMap fragment = null; @ViewInject (R.id.map) private MapView
Mapview;
private AMap aMap;
private View mapLayout; public static fragment newinstance () { if (fragment == null) { synchronized (Fragmentmap.class) { if (fragment == null) { &nbSp; fragment = new fragmentmap (); } } return
fragment; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP} public view oncreateview ( Layoutinflater inflater, viewgroup container, bundle savedinstancestate) { if (maplayout == null) {
Maplayout = inflater.inflate (R.layout.fragment_map, null); viewutils.inject (This, maplayoUT); mapview.oncreate (savedinstancestate);/must write if (amap == null) {
amap = mapview.getmap (); } else { if ( Maplayout.getparent () != null) { ((viewgroup)
Maplayout.getparent ()). Removeview (Maplayout); &NBSP} } return maplayout; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP} @Override public void onresume () {
super.onresume ();
mapview.onresume (); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP} /** * methods must rewrite the * map lifecycle method */ @ Override public void onpause () {
super.onpause ();
mapview.onpause (); &NBSP;&NBSP;&NBSP;&NBSP} /** * method must override * Life cycle method of map */ @Override puBlic void onsaveinstancestate (bundle outstate) {
Super.onsaveinstancestate (outstate);
mapview.onsaveinstancestate (outstate); &NBSP;&NBSP} /** * methods must override the * map lifecycle method */ @Override public void ondestroy () {
super.ondestroy ();
mapview.ondestroy (); } }
The effect chart is as follows: