Register for Baidu Developer account, download the relevant SDK
Add Permissions:
Add Baidu Registered Access application (AK) code
Add source code files to the Libs file:
The code is as follows:
1 PackageCom.lixu.baidu_gps;2 3 Importcom.baidu.location.BDLocation;4 ImportCom.baidu.location.BDLocationListener;5 Importcom.baidu.location.LocationClient;6 Importcom.baidu.location.LocationClientOption;7 8 Importandroid.app.Activity;9 ImportAndroid.os.Bundle;Ten ImportAndroid.widget.Toast; One A Public classMainactivityextendsActivity { - PrivateLocationclient mlocationclient =NULL; - the @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); + -Mylocationlistenner Mylistenner =NewMylocationlistenner (); + AMlocationclient =NewLocationclient ( This); atlocationclientoption option =Newlocationclientoption (); - -Option.setisneedaddress (true); -Option.setaddrtype ("All"); - mlocationclient.setlocoption (option); - Mlocationclient.registerlocationlistener (mylistenner); in Mlocationclient.start (); - to } + - Private classMylocationlistennerImplementsBdlocationlistener { the * @Override $ Public voidonreceivelocation (bdlocation location) {Panax Notoginseng //Get Province -String p =location.getprovince (); the //get the city +String City =location.getcity (); A //Get Road name theString Street =Location.getstreet (); + //Get Street number -String n =Location.getstreetnumber (); $Toast.maketext (Getapplicationcontext (), "Your present position in:" + P + "" + City + "" + Street + "" + N, 1). Show (); $ } - - } the - //shutdown when program exitsWuyi @Override the protected voidOnDestroy () { - Super. OnDestroy (); Wu mlocationclient.stop (); - } About $}
After running on the real machine, you will be displayed with the detailed address ...
Get address information using the Baidu Map open Source SDK.