How to get the Android GPS

Source: Internet
Author: User

How to get the Android GPS

In fact, this is a pseudo-proposition, because I am not to say that the Android GPS access implementation, or the bottom-level implementation, but I directly use the Baidu map of the SDK, in which the direct access to GPS information, previously have done this function, today will be directly introduced to the demo to benefit everyone.

First step: Get the SDK

Baidu Map of the developer on the Internet can be downloaded directly to the thread of the demo, of course, the function is relatively complete, the basic solution requires a variety of map functions. Http://developer.baidu.com/map/index.php?title=androidsdk

Step two, get the key

Refer to official website

Step three, use the map

The use of Baidu map last year when the key is written or in the function, and now has been placed in the Androidmanifest.xml file, a service is configured in this file, a meta data is OK, configuration is relatively simple; add the C used in the Libs + + library file, and Baidu developed a jar package. These configurations make it possible to get GPS data directly.

Note: Getting GPS data is more than once, or it takes time to get it, so you have to start a new thread and keep getting it until you get GPS information.

In my demo I wrote a new class to better encapsulate the use of Baidu Map class, of course, I think the code is more intuitive, no excessive consideration of performance problems, we can directly refer to the demo Baidu.

New Thread (Newrunnable () {           @Override public           void Run () {              //TODO auto-generated method stubs for              (int i = 0; I < 10; i++)              {                  try {                     thread.sleep ($);                  } catch (Interruptedexception e) {                     //TODO auto-generated catch block                     e.printstacktrace ();                  }              System.out.println ("oncreat1" + "\ n" + "Longitude:" +loc.getjingdu () + "\ n" + "Latitude:" +loc.getweidu () +                     "\ n" + "place Name:" + Loc.getdiming ());}}       ). Start ();

SOURCE download

How to get the Android GPS

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.