In the application development, map development is often needed to use the "component", the domestic more famous is Baidu map and the German map.
This blog is about the German map to achieve positioning and 3D map display, and labeling the corresponding location, words not much to say, first look at the effect, in the code.
Effect
First sign up to become a developer (open the Gao de map, click on the developer platform at the bottom), create an app, fill in the appropriate information as required, such as:
En route contains the release version of the SHA1 security Code and beta SHA1 Security Code, the values of both can be seen blog: Android Studio apk Packaging, Keystore.jks file generation, according to the KeyStore key to obtain SHA1 security code
Speak in a very detailed, according to do will be successful to obtain.
First import the Gold jar package
Select the jar package right click on the ADD as Library, see the following code in Build.fradle to indicate the success of the guide package
compile files(‘libs/AMap_Location_V3.0.0_20160922.jar‘) compile files(‘libs/AMap_Search_V3.5.0_20160927.jar‘) compile files(‘libs/AMap_3DMap_V4.1.1_20161019.jar‘)
Code: (Note: The Project code directory to add an interface file Jnilibs OS file to draw the map, specific download source view, it is not described in detail)
/**** * V. Gold map positioning and 3D map display * * Packaging and unpackaged cases are not the same, the German configuration is configurable debug and release version * */public class Mainactivity extends Appcompatactivity imple ments Amaplocationlistener,geocodesearch.ongeocodesearchlistener {private amaplocationclient locationClient = null; Private amaplocationclientoption locationoption = null; Private TextView TextView; Private string[] STRMSG; Private Com.amap.api.maps.AMap AMAP; Private Mapview Mapview; Private Geocodesearch Geocodersearch; Private Marker Geomarker; private static Latlonpoint Latlonpoint; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); TextView = (TextView) Findviewbyid (R.ID.TEXT_MAP); Mapview = (Mapview) Findviewbyid (R.ID.MAP); Mapview.oncreate (savedinstancestate);//This method must override location (); private void Initmap () {if (AMap = = null) {AMap = Mapview.getmap (); With the German default icon Geomarker= Amap.addmarker (New Markeroptions (). Anchor (0.5f, 0.5f). Icon (Bitmapdescriptorfactory.defaultmarker (B (Itmapdescriptorfactory.hue_blue))); The custom icon Geomarker = Amap.addmarker (new Markeroptions (). Anchor (0.5f, 0.5f). Icon (Bitmapdescrip Torfactory.frombitmap (Bitmapfactory.decoderesource (Getresources (), r.mipmap.punch_dw))); } Geocodersearch = new Geocodesearch (this); Geocodersearch.setongeocodesearchlistener (this); GetAddress (Latlonpoint); } @Override public void onlocationchanged (Amaplocation loc) {if (null! = Loc) {Message msg = MHa Ndler.obtainmessage (); Msg.obj = loc; Msg.what = Utils.msg_location_finish; Mhandler.sendmessage (msg); }} Handler Mhandler = new Handler () {public void DispatchMessage (Android.os.Message msg) {SWITC H (msg.what) {//Position complete case utils.msg_location_finish: String result = ""; try {amaplocation loc = (amaplocation) msg.obj; result = Utils.getlocationstr (loc, 1); STRMSG = Result.split (","); Toast.maketext (Mainactivity.this, "positioning success", Toast.length_long). Show (); Textview.settext ("Address:" + strmsg[0] + "\ n" + "Longitude:" + strmsg[1] + "\ n" + "Latitude:" + strmsg[2]); latlonpoint= New Latlonpoint (Double.valueof (strmsg[2]), double.valueof (strmsg[1])); Initmap (); } catch (Exception e) {toast.maketext (Mainactivity.this, "failed to locate", Toast.length_long). Show (); } break; Default:break; } }; }; public void location () {//TODO auto-generated Method stub try {locationclient = new Amaplocati Onclient (this); Locationoption = new Amaplocationclientoption (); Set the positioning mode to low power mode Locationoption.setlocationmode (AMapLocationClientOption.AMapLocationMode.Battery_Saving); Set the location monitoring Locationclient.setlocationlistener (this); Locationoption.setoncelocation (TRUE);//set to one-time positioning locationclient.setlocationoption (locationoption);//Set positioning parameters Start positioning locationclient.startlocation (); Mhandler.sendemptymessage (Utils.msg_location_start); } catch (Exception e) {toast.maketext (Mainactivity.this, "failed to locate", Toast.length_long). Show (); }}/** * response inverse geocoding */public void getaddress (final latlonpoint latlonpoint) {regeocodequery query = new Regeocodequery (Latlonpoint, S, geocodesearch.amap);//The first parameter represents a LATLNG, the second parameter represents the range of meters, the third parameter indicates the fire coordinate system or GP s native coordinate system Geocodersearch.getfromlocationasyn (query);//Set Synchronous inverse geocoding Request}/** * GeoCode query callback */@Overridepublic void ongeocodesearched (geocoderesult result, int rCode) {}/** * Inverse geocoding callback */@Override public V OID onregeocodesearched (regeocoderesult result, int rCode) {if (RCode = =) {if (result! = NULL &am p;& result.getregeocodeaddress ()! = null && result.getregeocodeaddress (). Getformataddress () ! = null) {Toast.maketext (Mainactivity.this,result.getregeocodeaddress (). Getformataddress () + "Nearby", Toast.length_long). Show (); Amap.animatecamera (Cameraupdatefactory.newlatlngzoom (AMAPUTIL.CONVERTTOLATLNG (latLonPoint), 15)); Geomarker.setposition (AMAPUTIL.CONVERTTOLATLNG (latlonpoint)); } else {}} else {}}/** * method must be overridden */@Override public void Onresume () { Super.onresume (); Mapview.onresume (); }/** * method must be rewritten */@Override public void OnPause () { Super.onpause (); Mapview.onpause (); }/** * method must be rewritten */@Override public void Onsaveinstancestate (Bundle outstate) {Super.onsaveinstanc EState (outstate); Mapview.onsaveinstancestate (outstate); } @Override public void OnDestroy () {Super.ondestroy (); Mapview.ondestroy (); }}
Adding Permissions in Androidmanifest.xml
<!--allow programs to open network Sockets--<uses-permission android:name= "Android.permission.INTERNET"/> <!--positioning--and lt;! --for access to GPS positioning--<uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION" ></ uses-permission> <uses-permission android:name= "Android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" >< /uses-permission> <!--allows programs to set write permissions for the built-in SD card--<uses-permission android:name= "android.permission.WRITE_ External_storage "/> <!--allow programs to get network status--<uses-permission android:name=" android.permission.ACCESS_ Network_state "/> <!--allow programs to access WiFi network information-<uses-permission android:name=" android.permission.ACCESS_WIFI_ State "/> <!--allows programs to read and write phone status and identity--<uses-permission android:name=" Android.permission.READ_PHONE_STATE "/> ; <!--allows programs to access cellid or WiFi hotspots to get a rough location--<uses-permission android:name= "android.permission.ACCESS_COARSE_ Location "/>
If you only implement high-de positioning, you can view: Achieve high-de location and get information in Android Studio
Speak in a very detailed, please leave a message in doubt.
SOURCE Click to download
Android Studio's high-de map for positioning and 3D map display