Baidu Map API Positioning--third party open source--Baidu map (a)

Source: Internet
Author: User

1. Copy the Libs from the Baidu Map location API (: http://lbsyun.baidu.com/sdk/download?selected=location) to your project Libs

2. Make the relevant configuration, see the Official document: http://developer.baidu.com/map/index.php?title=android-locsdk/guide/v5-0

3. Code:

1  PackageCom.zzw.baidumap;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.util.Log; One  A  Public classMainactivityextendsActivity { - locationclient mlocationclient; -  the @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - //Setcontentview (r.layout.activity_main); +  -         //Get Locationclient +Mlocationclient =NewLocationclient ( This); A  at         //Get Locationlistenner -Mylocationlistenner Mlistenner =NewMylocationlistenner (); -  -         //Set locationclient options -locationclientoption option =Newlocationclientoption (); -Option.setisneedaddress (true); inOption.setaddrtype ("All"); -Option.setcoortype ("Bd09ll");//set to Baidu's positioning type to  + mlocationclient.setlocoption (option); -  the         //Register Locationlistener * Mlocationclient.registerlocationlistener (mlistenner); $ Panax Notoginseng         //start Start - Mlocationclient.start (); the     } +  A @Override the     protected voidOnDestroy () { +         //End Startup - mlocationclient.stop (); $         Super. OnDestroy (); $     } -  -     //Specific Operation the     Private classMylocationlistennerImplementsBdlocationlistener { - Wuyi @Override the          Public voidonreceivelocation (bdlocation location) { -             Try { Wu                 //the province where the current device location is located -String province =location.getprovince (); AboutLOG.D ("province", province); $  -                 //the city where the current device is located: For example, Chengdu -String City =location.getcity (); -LOG.D ("City", city); A  +                 //specific address: from the country to the street--xx xx province, China xx xx Road XX No.-attached x theString Addestr =location.getaddrstr (); -LOG.D ("Addestr", addestr); $  the                 //National theString Country =location.getcountry (); theLOG.D ("Country", country); the  -                 //areas, such as: Jinniu District inString district =location.getdistrict (); theLOG.D ("District", district); the  About                 //streets such as: South Road theString Street =Location.getstreet (); theLOG.D ("Street", street); the  +                 //specific street numbers such as: 60th-attached 2 -String Streetnumber =Location.getstreetnumber (); theLOG.D ("Streetnumber", streetnumber);Bayi  the                 //Current Time theString time =location.gettime (); -LOG.D ("Time", time); -  theLOG.D ("Current Position", addestr); the}Catch(Exception e) { the e.printstacktrace (); the             } -  the         } the  the     }94}

Baidu Map API Positioning--third party open source--Baidu map (a)

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.