Android Studio's high-de map for positioning and 3D map display

Source: Internet
Author: User
Tags sha1

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)

/*** * to tell the German map location and 3D Map display * * Packaging and unpackaged cases are not the same, the German configuration is configurable debug and release version **/ Public classMainactivityextendsAppcompatactivityImplementsAmaplocationlistener,geocodesearch.ongeocodesearchlistener {PrivateAmaplocationclient locationclient =NULL; PrivateAmaplocationclientoption locationoption =NULL; PrivateTextView TextView; Privatestring[] STRMSG; PrivateCom.amap.api.maps.AMap AMAP; PrivateMapview Mapview; PrivateGeocodesearch Geocodersearch; PrivateMarker Geomarker; Private StaticLatlonpoint Latlonpoint; @Overrideprotected voidonCreate (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 theLocation (); }    Private voidInitmap () {if(AMap = =NULL) {AMap=Mapview.getmap (); //with the German default icon//geomarker= Amap.addmarker (New Markeroptions (). Anchor (0.5f, 0.5f). Icon (Bitmapdescriptorfactory.defaultmarker (            (Bitmapdescriptorfactory.hue_blue))); //Custom IconsGeomarker = Amap.addmarker (NewMarkeroptions (). Anchor (0.5f, 0.5f). Icon (Bitmapdescriptorfactory.frombitmap (Bitmapfactory.decoderesource (Getresources (), R.mipmap.pun        CH_DW))); } Geocodersearch=NewGeocodesearch ( This); Geocodersearch.setongeocodesearchlistener ( This);    GetAddress (Latlonpoint); } @Override Public voidonlocationchanged (Amaplocation Loc) {if(NULL!=Loc) {Message msg=Mhandler.obtainmessage (); Msg.obj=Loc; Msg.what=Utils.msg_location_finish;        Mhandler.sendmessage (msg); }} Handler Mhandler=NewHandler () { Public voidDispatchMessage (android.os.Message msg) {Switch(msg.what) {//Positioning Complete                 CaseUtils.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=NewLatlonpoint (Double.valueof (strmsg[2]), double.valueof (strmsg[1]));                    Initmap (); } Catch(Exception e) {toast.maketext (mainactivity. This, "Location failed", Toast.length_long). Show (); }                     Break; default:                     Break;    }        };    };  Public voidLocation () {//TODO auto-generated Method Stub        Try{locationclient=NewAmaplocationclient ( This); Locationoption=Newamaplocationclientoption (); //set the positioning mode to low power modeLocationoption.setlocationmode (AMapLocationClientOption.AMapLocationMode.Battery_Saving); //Setting up location monitoringLocationclient.setlocationlistener ( This); Locationoption.setoncelocation (true);//set to one-time positioningLocationclient.setlocationoption (locationoption);//Set Positioning parameters//Start Positioninglocationclient.startlocation ();        Mhandler.sendemptymessage (Utils.msg_location_start); } Catch(Exception e) {toast.maketext (mainactivity. This, "Location failed", Toast.length_long). Show (); }    }    /*** Response Inverse geocoding*/     Public voidGetAddress (Finallatlonpoint Latlonpoint) {regeocodequery Query=NewRegeocodequery (Latlonpoint, 200, geocodesearch.amap);//The first parameter represents a LATLNG, the second parameter represents the range of meters, and the third parameter indicates whether it is a fire coordinate system or a GPS native coordinate systemGeocodersearch.getfromlocationasyn (query);//set up synchronous inverse geocoding requests    }    /*** geo-coded query callback*/@Override Public voidongeocodesearched (geocoderesult result,intRCode) {    }    /*** Inverse geocoding callback*/@Override Public voidonregeocodesearched (regeocoderesult result,intRCode) {        if(RCode = = 1000) {            if(Result! =NULL&& 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 voidOnresume () {Super. Onresume ();    Mapview.onresume (); }    /*** method must be overridden*/@Override Public voidOnPause () {Super. OnPause ();    Mapview.onpause (); }    /*** method must be overridden*/@Override Public voidonsaveinstancestate (Bundle outstate) {Super. Onsaveinstancestate (outstate);    Mapview.onsaveinstancestate (outstate); } @Override Public voidOnDestroy () {Super. OnDestroy ();    Mapview.ondestroy (); }}

Adding Permissions in Androidmanifest.xml

<!--allow programs to open network sockets -    <uses-permissionAndroid:name= "Android.permission.INTERNET" />    <!--positioning -    <!--used to access GPS positioning -    <uses-permissionAndroid:name= "Android.permission.ACCESS_FINE_LOCATION"></uses-permission>    <uses-permissionAndroid:name= "Android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>    <!--allow programs to set write permissions on the built-in SD card -    <uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE" />    <!--allow programs to get network status -    <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE" />    <!--allow programs to access WiFi network information -    <uses-permissionAndroid:name= "Android.permission.ACCESS_WIFI_STATE" />    <!--allows programs to read and write phone status and identity -    <uses-permissionAndroid:name= "Android.permission.READ_PHONE_STATE" />    <!--allow programs to access cellid or WiFi hotspots to get a rough location -    <uses-permissionAndroid:name= "Android.permission.ACCESS_COARSE_LOCATION" />

Add key value information to the <application> tag

< Meta-data   Android:name = "Com.amap.api.v2.apikey"   android:value= "32c4bc659a111616d9b1196522223206"></meta-data >   <!--  -<android:name = " Com.amap.api.location.APSService "></service>

If you only implement high-de positioning, you can view: Achieve high-de location and get information in Android Studio

It's a very detailed story.

SOURCE Click to download

Android Studio's high-de map for positioning and 3D map display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.