Baidu Map SDK Use

Source: Internet
Author: User

First step: Get the key

Application name can be filled in casually

The release version of SHA1 gets the

Keytool-v-list-keystore:c:\users\admin\.android\debug.keystore Press ENTER

The Get password is not visible when Android input, but it is actually entered by pressing ENTER

Can get SHA1.

Next Download the latest

After download is

Copy this file to

And then, in Androidmanifest, remember the permissions.

Environment and well-equipped

2: Code

1  Public classMainactivityextendsappcompatactivity {2 3      PublicLocationclient mlocationclient =NULL;4      PublicBdlocationlistener MyListener =NewMylocationlistener ();5 6 @Override7     protected voidonCreate (Bundle savedinstancestate) {8         Super. OnCreate (savedinstancestate);9 Setcontentview (r.layout.activity_main);Ten  OneMlocationclient =NewLocationclient (Getapplicationcontext ());//declaring the Locationclient class AMlocationclient.registerlocationlistener (MyListener);//registering the Listener function -Initlocation ();//Initialize -Mlocationclient.start ();//Start Positioning the     } -  -     Private voidinitlocation () { -locationclientoption option =Newlocationclientoption (); + Option.setlocationmode (LocationClientOption.LocationMode.Hight_Accuracy -);//Optional, default high precision, set positioning mode, high accuracy, low power, device only +Option.setcoortype ("Bd09ll");//Optional, default GCJ02, set the returned positioning result coordinate system A         intspan = 1000; atOption.setscanspan (span);//Optional, default 0, that is, to locate only once, set the interval for initiating a location request is greater than or equal to 1000ms is valid -Option.setisneedaddress (true);//Optional, set whether address information is required, default does not require -Option.setopengps (true);//Optional, default false to set whether to use GPS -Option.setlocationnotify (true);//Optional, default false to set whether GPS results are output according to 1S1 frequency when GPS is active -Option.setisneedlocationdescribe (true);//optional, default false, setting whether to need positional semantics results, can be obtained in bdlocation.getlocationdescribe, the result is similar to "near the gate of the Beijing Cheonan" -Option.setisneedlocationpoilist (true);//optional, default false, set whether POI results are required, can be obtained in bdlocation.getpoilist inOption.setignorekillprocess (false);//Optional, default True, the location SDK inside is a service, and put into a standalone process, set whether to kill the process at stop, the default does not kill -Option. Setignorecacheexception (false);//optional, default false, sets whether to collect crash information, default collection toOption.setenablesimulategps (false);//Optional, default false to set whether the GPS simulation results need to be filtered, by default + mlocationclient.setlocoption (option); -     } the  *      Public classMylocationlistenerImplementsBdlocationlistener { $ @OverridePanax Notoginseng          Public voidonreceivelocation (bdlocation location) { -             //Receive Location theStringBuffer SB =NewStringBuffer (256); +Sb.append ("Time:"); A Sb.append (Location.gettime ()); theSb.append ("\nerror Code:"); + Sb.append (Location.getloctype ()); -Sb.append ("\nlatitude:"); $ Sb.append (Location.getlatitude ()); $Sb.append ("\nlontitude:"); - Sb.append (Location.getlongitude ()); -Sb.append ("\nradius:"); the Sb.append (Location.getradius ()); -             if(Location.getloctype () = = bdlocation.typegpslocation) {//GPS Positioning ResultsWuyiSb.append ("\nspeed:"); theSb.append (Location.getspeed ());//unit: km/h -Sb.append ("\nsatellite:"); Wu Sb.append (Location.getsatellitenumber ()); -Sb.append ("\nheight:"); AboutSb.append (Location.getaltitude ());//Unit: M $Sb.append ("\ndirection:"); -Sb.append (Location.getdirection ());//Unit degree -Sb.append ("\NADDR:"); - Sb.append (Location.getaddrstr ()); ASb.append ("\ndescribe:"); +Sb.append ("GPS positioning Success"); the  -}Else if(Location.getloctype () = = bdlocation.typenetworklocation) {//Network Positioning Results $Sb.append ("\NADDR:"); the Sb.append (Location.getaddrstr ()); the                 //Carrier Information theSb.append ("\noperationers:"); the Sb.append (Location.getoperators ()); -Sb.append ("\ndescribe:"); inSb.append ("Network positioning Success"); the}Else if(Location.getloctype () = = bdlocation.typeofflinelocation) {//offline targeting results theSb.append ("\ndescribe:"); AboutSb.append ("Offline positioning is successful, offline location results are also effective"); the}Else if(Location.getloctype () = =bdlocation.typeservererror) { theSb.append ("\ndescribe:"); theSb.append ("Server-side network location failed, can be feedback IMEI number and the approximate location of the time to [email protected], someone will be traced to the reason"); +}Else if(Location.getloctype () = =bdlocation.typenetworkexception) { -Sb.append ("\ndescribe:"); theSb.append ("Network different causes location failure, please check the network is unobstructed");Bayi}Else if(Location.getloctype () = =bdlocation.typecriteriaexception) { theSb.append ("\ndescribe:"); theSb.append ("Unable to obtain an effective location based on the location failure, is generally due to the cause of the phone, in flight mode is generally caused by this result, you can try to focus on the mobile phone"); -             } -Sb.append ("\nlocationdescribe:"); theSb.append (Location.getlocationdescribe ());//Location Semantics Information thelist<poi> list = Location.getpoilist ();//POI Data the             if(List! =NULL) { theSb.append ("\npoilist size =:"); - Sb.append (List.size ()); the                  for(Poi p:list) { theSb.append ("\npoi=:"); theSb.append (P.getid () + "" + p.getname () + "" +P.getrank ());94                 } the             } the             //Output Information theLOG.D ("Baidulocationapidem", sb.tostring ());98 mlocationclient.stop (); About         } -     }101 102}

And then the logs will print.

Baidu Map SDK Use

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.