Positioning of the Android German map

Source: Internet
Author: User
Tags sha1

Look at the comment parsing is basically OK.

Layout, Permissions:

<!--for network positioning --    <uses-permission android:name="Android.permission.ACCESS_COARSE_LOCATION"> </uses-permission>    <!--for access to GPS location --    <uses-permission android:name="Android.permission.ACCESS_FINE_LOCATION" ></uses-permission>    <!--get carrier information to support interfaces that provide operator information--    <uses-permission android:name="Android.permission.ACCESS_NETWORK_STATE"> </uses-permission>    <!--used to access WiFi network information, WiFi information is used for network location--    <uses-permission android:name="Android.permission.ACCESS_WIFI_STATE"> </uses-permission>    <!--this permission to get access to WiFi, WiFi information is used for network location --    <uses-permission android:name="Android.permission.CHANGE_WIFI_STATE"></uses-permission>    <!--for network access, network targeting requires internet--    <uses-permission android:name="Android.permission.INTERNET"></uses-permission>    <!--to read the current state of the phone--    <uses-permission android:name="Android.permission.READ_PHONE_STATE" ></uses-permission>    <!--write to the extended storage, write data to the expansion card for write cache location data- -    <uses-permission android:name="Android.permission.WRITE_EXTERNAL_STORAGE"> </uses-permission>
<meta-data  android:name  = "Com.amap.api.v2.apikey"  android:value  = "your key" />  Span class= "Hljs-tag" ><service  android:name  = "Com.amap.api.location.APSService" ;  service ;   
<com.amap.api.maps.MapView        android:id="@+id/map"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_below="@+id/my_location">    </com.amap.api.maps.MapView>
 Public  class mainactivity extends appcompatactivity  implements  Locationsource,amaplocationlistener {    PrivateAMap AMap;PrivateOnlocationchangedlistener Mlistener;PrivateMapview Mmapview;//Declare Amaplocationclient class object     PublicAmaplocationclient maplocationclient;//Declare Amaplocationclientoption object     PublicAmaplocationclientoption maplocationclientoption;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Getsupportactionbar (). Hide ();        Setcontentview (R.layout.activity_main); Mmapview = (Mapview) Findviewbyid (R.ID.MAP);//Perform mmapview.oncreate (savedinstancestate) when activity executes onCreate to achieve map life cycle managementMmapview.oncreate (savedinstancestate);if(amap==NULL) {AMap = Mmapview.getmap (); } amap.setlocationsource ( This);//Set Location monitoringAmap.getuisettings (). setmylocationbuttonenabled (true);//Sets whether the default positioning button is displayed        //set to True to show the positioning layer and trigger positioning, false to hide the anchor layer and not trigger positioning, false by defaultAmap.setmylocationenabled (true);The type of positioning is positioning mode, which can be rotated by positioning, following, or map according to orientation.Amap.setmylocationtype (amap.location_type_locate); }@Override    protected void OnDestroy() {Super. OnDestroy ();//Perform Mmapview.ondestroy () when activity executes OnDestroy to achieve map life cycle managementMmapview.ondestroy ();    Maplocationclient.ondestroy (); }@Override    protected void Onresume() {Super. Onresume ();//Perform mmapview.onresume () when activity executes onresume to achieve map life cycle managementMmapview.onresume (); }@Override    protected void OnPause() {Super. OnPause ();//Perform mmapview.onpause () when activity executes onPause to achieve map life cycle managementMmapview.onpause (); }@Override    protected void OnStop() {Super. OnStop ();    Maplocationclient.stoplocation (); }@Override    protected void onsaveinstancestate(Bundle outstate) {Super. Onsaveinstancestate (Outstate);//Perform mmapview.onsaveinstancestate (outstate) when activity executes onsaveinstancestate to achieve map life cycle managementMmapview.onsaveinstancestate (outstate); }@Override     Public void onlocationchanged(Amaplocation amaplocation) {if(amaplocation!=NULL){if(Amaplocation.geterrorcode () = =0) {mlistener.onlocationchanged (amaplocation);//Display system small blue dotStringBuilder StringBuilder =NewStringBuilder ();//Locate successful callback information, set related message                intType = Amaplocation.getlocationtype ();                String address = amaplocation.getaddress ();                Stringbuilder.append (type+address); Toast.maketext ( This, Stringbuilder.tostring (), Toast.length_short). Show (); }Else{//Display error message Errcode is error code, Errinfo is error message, see below error code table. LOG.I ("Erro info:", Amaplocation.geterrorcode () +"---"+amaplocation.geterrorinfo ()); }        }    }//Activate positioning    @Override     Public void Activate(Onlocationchangedlistener Onlocationchangedlistener) {Mlistener = Onlocationchangedlistener;if(maplocationclient==NULL){//Initialize the amaplocationclient, and bind the listenerMaplocationclient =NewAmaplocationclient (Getapplicationcontext ());//Initialize positional parametersMaplocationclientoption =NewAmaplocationclientoption ();//Set positioning accuracyMaplocationclientoption.setlocationmode (AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//Whether to return address informationMaplocationclientoption.setneedaddress (true);//Whether to locate only onceMaplocationclientoption.setoncelocation (false);//Set whether to force refresh WiFi, default to force refreshMaplocationclientoption.setwifiactivescan (true);//Whether to allow analog locationMaplocationclientoption.setmockenable (false);//Positioning time intervalMaplocationclientoption.setinterval ( -);//Set positioning parameters for locating client ObjectsMaplocationclient.setlocationoption (maplocationclientoption);//Binding monitoringMaplocationclient.setlocationlistener ( This);//Open positionMaplocationclient.startlocation (); }    }//Stop positioning    @Override     Public void Deactivate() {Mlistener =NULL;if(maplocationclient!=NULL) {maplocationclient.stoplocation ();        Maplocationclient.ondestroy (); } maplocationclient =NULL; }/** 0 positioned successfully.     1 Some important parameters are null, such as context; make a non-null judgment on the parameters of the positional pass.     2 failed to locate because only a single wifi was scanned and no base station information was available.     3 Gets the request parameter to NULL, possibly an exception occurred during the fetch.     4 the exception in the request server process, many network conditions are poor, link is not the cause, please check the device network is unobstructed.     5 XML Format error returned, parsing failed.     6 Location Service Return location failed, if this exception occurs, please send errordetail information through [email protected] feedback to us.     7 Key failed to build, please double check the key binding SHA1 value and APK signature SHA1 value corresponds.     8 Android Exception General error, please send errordetail information through [email protected] feedback to us.     9 An exception occurred while locating initialization, please restart the location.     10 locating the client failed to start, please check if the Androidmanifest.xml file is configured with Apsservice location Service 11 when locating the base station information error, please check whether the SIM card is installed, the device is likely to be connected to the pseudo-base station network.     12 The location permission is missing, turn on the app's location in the settings of your device. **/}

Positioning of the Android German map

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.