Core API for GPS support

Source: Internet
Author: User

Android provides a Locationmanager class specifically for GPs support, which acts similarly to service classes such as Telephonymanager, Audiomanager, and all GPS-targeting related services, Object will be generated by the object.

Similar to the method of obtaining Telephonymanager and Audiomanager in the program, the program does not directly Locationmanager instances, but is obtained by invoking the Getsystemservice () method of the context. For example, the following code:

Locationmanager lm = Getsystemservice (Context.location_service);

Once the Locationmanager object has been obtained in the program, the class can then call Locationmanager's method to obtain the related services and objects for GPS positioning. Locationmanager provides the following common methods:

1. Boolean Addgpsstatuslistener (Gpsstatus.listener Listener): Add a listener that listens for GPS status.

2. void Addproximityalert (double latitude, double longitude, float radius, long expiration, pendingintent intent ): Add a proximity warning.

3, List<string> getallproviders (): Get all the Locationprovider list.

4. String Getbestprovider (Criteria, Boolean enabledonly): Returns the optimal Locationprovider object based on the specified criteria.

5, Gpsstatus getgpsstatus (gpsstatus status): Get GPS status.

6. Location Getlastknownlocation (String provider): Gets the last known location based on Locationprovider.

7, Locationprovider Getprovider (String name): Gets Locationprovider by name.

8, list<string> Getproviders (criteria, Boolean enabledonly): Gets the name of all Locationprovider that satisfy the condition, based on the specified criteria.

9, List<string> getproviders (boolean enabledonly): Gets all the available locationprovider.

10, Boolean isproviderenabled (String provider): Determines whether Locationprovider of the specified name is available.

11, void Removegpsstatuslistener (Gpsstatus.listener Listener): Delete GPS status listener.

12. Void Removeproximityalert (Pendingintent intent): Deletes a nearby warning.

13. Void Requestlocationupdates (String provider, long Mintim, float mindistance, pendingintent intent): via the specified location The provider periodically acquires the location information and triggers the corresponding trigger of the listener.

In the list of methods above, there is another important API supported by GPS:Locationprovider (location provider), the Locationprovider object is the abstract representation of the GPS positioning component, With Locationprovider, you can get information about the positioning component, and Locationprovider provides the following common methods:

1, int getaccuracy (): Returns the precision of the locationprovider.

2. String getName (): Returns the name of the Locationprovider.

3, int getpowerrequirement (): Gets the power requirement of the locationprovider.

4. Boolean hasmonetarycost (): Returns whether the Locationprovider is chargeable or free.

5, Boolean Meetscriteria (criteria): To determine whether the Locationprovider meet the criteria.

6, Boolean Requirescell (): Determine whether the locationprovider need to access the network base station.

7. Boolean requiresnetwork (): Determine if the Locationprovider requires network data.

8, Boolean requiressatellite (): Determine whether the locationprovider need to access satellite-based positioning system.

9. Boolean supportsaltitude (): Determines whether the Locationprovider supports height information.

10. Boolean supportsbearing (): Determines whether the locationprovider supports directional information.

11. Boolean supportsspeed (): Determines whether the Locationprovider supports speed information.

In addition to this, GPS support also hasan API: location, which is an abstract class representing positional information and provides the following methods for locating information.

1. Float getaccuracy (): Gets the accuracy of the positioning information.

2, Double getaltitude (): Gets the height of the location information.

3. Float getbearing (): Gets the orientation of the positioning information.

4, Double getlatitude (): Gets the latitude of the location information.

5, double getlongitude (): Gets the longitude of the location information.

6. String Getprovider (): Gets the Locationprovider that provides the location information.

7. Float getspeed (): Gets the speed of the location information.

8, Boolean hasaccuracy (): Determine whether the positioning information has precision information.

9. Boolean hasaltitude (): Determine if the location information has a high level of information.

10, Boolean hasbearing (): Determine whether the location information has direction information.

11, Boolean Hasspeed (): Determine whether the location information has speed information.

The above three APIs are the three core APIs supported by Android GPS, and the general steps for using them to obtain GPS location information are:

1. Get the Locationmanager object of the system.

2, using Locationmanager, by specifying the Locationprovider to obtain positioning information, positioning information is represented by the Location object.

3. Obtain positioning information from the Location object.

Core API for GPS support

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.