Android – Location Manger

The LocationManager Service is offered by the android.location package. There are three types of location providers:
1. GPS
2. Network – Use cell-phone towers or Wi-Fi networks
3. The Passive provider and it is like a location update sniffer

Here is the example:

public class MyApplication extends Application implements LocationListener {

private static MyApplication instance;

public void onCreate() {
  super.onCreate();
  instance = this;
  LocationManager locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
  locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, this);

}

public static Context getContext() {
  return instance;
}

public void onLocationChanged(Location location) {
   Log.i("Debug"," OnLocation Changed"+ location.getLatitude() + " " + location.getLongitude());

}

public void onProviderDisabled(String provider) {

}

public void onProviderEnabled(String provider) {

}

public void onStatusChanged(String provider, int status, Bundle extras) {

}

Leave a comment