Get address information using the Baidu Map open Source SDK.

Source: Internet
Author: User


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.

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.