Android Positioning System (GPS) development detailed _android

Source: Internet
Author: User
Tags reverse geocoding

The Global Positioning System (positioning System,gps) is a medium-range circular orbiting satellite navigation system that provides accurate positioning, speed measurement and high precision time standards for the vast majority of the Earth's surface (98%). GPS is widely used in military, logistics, geography, mobile phones, digital cameras, aviation and other fields, has a very powerful function.

Android supports geolocation services APIs. The geolocation service can be used to obtain the location of the current device, and the application can periodically request updates to the current location of the device. For example, an application can use a intent receiver to implement the following functions:

Planning an area with latitude and longitude, when the device enters the area, sends out reminders, and can be used with the Google Map API to accomplish more tasks.

The APIs for geo-positioning systems are all located in the Android.location package, which includes several important functional classes:

Locationmanager:

This class provides access to location services and provides the ability to obtain the best location provider. In addition, the proximity alert feature can also be implemented with this class.

Locationprovide:

The class is an abstract class that locates the provider. The location provider has the ability to periodically report the location of the device.

Locationlistener:

Provides callback functionality when status information changes. You must register the listener object in the locator manager beforehand.

Criteria:

This class enables the application to select the appropriate location provider through the properties set in the Locationprovider.

Geocoder:

A class that deals with geocoding and reverse geo-coding. Geocoding refers to the transformation of addresses or other descriptions into longitude and latitude, and reverse geocoding is the conversion of longitude and latitude into address or description language, which contains two constructors and requires the passing of latitude and longitude coordinates. The Getfromlocation method can get a set of arrays about addresses.

To use geo-positioning, you first need to obtain an instance of Locationmanager, in Android, the only way to get Locationmanager is through the Getsystemservice () method call. By using Locationmanager, we can also get a list of location providers. In a real handheld device, this list includes some GPS services. We can also choose a more powerful, more accurate, not with other accessories service GPS. The code is as follows:

Locationmanager.requestlocationupdate (Locationmanager.gps_provider,1000,0,locationmanager);

After getting the Locationmanager object, we also need to register a periodic update view with the following code:

Locationmanager.requestlocationupdate (Locationmanager.gps_provider,1000,0,locationmanager);

The first parameter is to set the service provider, and the second parameter is the cycle, where you need to specify the last parameter Locationmanager, which listens for changes in location information, so we must implement the following methods:

onlocationchanged (Location Location):

When the coordinate changes, the secondary function is triggered, and if the provider passes the same coordinates, it will not trigger.

onproviderdisabled (String provider):

This function is triggered when provider is disabled, such as GPS shutdown.

onproviderenabled (Sting provider):

Provider enabled is to trigger this function, such as GPS being opened.

onstatuschanged (String provider, int status, Bundle extras):

This function is triggered when the state of the provider is switched directly between available, temporarily unavailable, and service-free three states.

The above is to the Android GPS data collation, the need for friends can refer to.

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.