Android offers a variety of location services:
(1) GPS (Global Positioning system using satellites);
(2) Network (base station location with Cell-id, Wi-Fi service address)
(3) Passive (API Level 8 added)
In the absence of special requirements, you can set the frequency of updates and reduce the number of requests. Register Listener, disable location monitoring when not in use
Accept Location Updates
private void Requestlocationupdates () {Locationmanager LM = (locationmanager) getsystemservice (context.location_ SERVICE); List<string> Provider = Lm.getallproviders (); if (provider! = NULL &&!provider.isempty ()) { Locationlistener listener = new Locationlistener () {@Overridepublic void onstatuschanged (String provider, int status, Bundle extras) {//Todo auto-generated method stub} @Overridepublic void Onproviderenabled (String provider) {//Todo auto-g enerated method stub} @Overridepublic void Onproviderdisabled (String provider) {//TODO auto-generated method stub}@ overridepublic void onlocationchanged (location location) {//TODO auto-generated method Stub}};for (String Name:provider {lm.requestlocationupdates (name, Dateutils.hour_in_millis * 1,100, listener);//Set the update frequency}}}//Logoff listener (the user can force a location to be fixed), Call private void Disablelocationlistener (Locationlistener listener) {Locationmanager LM = (locationmanager) where it needs to be called Getsystemservice (Context.location_service); Lm.removeupdates (listener);} Last known location (no need to start location services) Private Locations getlastknownlocation () {Locationmanager LM = (Locationmanager) getsystemservice ( Context.location_service); list<string> names = Lm.getallproviders (); Location Location=null;if (names!=null) {for (String name:names) {if (! LocationManager.PASSIVE_PROVIDER.equals (name)) {location l=lm.getlastknownlocation (name); if ((L!=null) && ( location==null| | L.gettime () >location.gettime ())) {location=l;}}} return location;}
Extended battery life--positioning