Advertisement
Ankhwatcher

Location Updates

Apr 6th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. protected Boolean locationUpdates(Boolean needed) {
  2.  
  3.         if (needed) {
  4.             locationManager = (LocationManager) CaptureRouteActivity.this.getSystemService(Context.LOCATION_SERVICE);
  5.  
  6.             networkListener = new LocationListener() {
  7.                 public void onLocationChanged(Location location) {
  8.                     makeUseOfNetwork(location);
  9.                 }
  10.  
  11.                 public void onStatusChanged(String provider, int status, Bundle extras) {
  12.                 }
  13.  
  14.                 public void onProviderEnabled(String provider) {
  15.                 }
  16.  
  17.                 public void onProviderDisabled(String provider) {
  18.                 }
  19.             };
  20.             gpsListener = new LocationListener() {
  21.                 public void onLocationChanged(Location location) {
  22.                     makeUseOfGPS(location);
  23.                 }
  24.  
  25.                 public void onStatusChanged(String provider, int status, Bundle extras) {
  26.                 }
  27.  
  28.                 public void onProviderEnabled(String provider) {
  29.                 }
  30.  
  31.                 public void onProviderDisabled(String provider) {
  32.                 }
  33.             };
  34.             /*
  35.              * Register the listener with the Location Manager to receive
  36.              * location updates
  37.              */
  38.             locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 000, 0, networkListener);
  39.             locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 000, 0, gpsListener);
  40.             locationManager=null;
  41.             /*
  42.              * The two integers in this request are the time (ms) and distance
  43.              * (m) intervals of notifications respectively.
  44.              */
  45.             return true;
  46.         }
  47.  
  48.         if (!needed) {
  49.  
  50.             locationManager = (LocationManager) CaptureRouteActivity.this.getSystemService(Context.LOCATION_SERVICE);
  51.  
  52.             networkListener = new LocationListener() {
  53.                 public void onLocationChanged(Location location) {
  54.                     makeUseOfNetwork(location);
  55.                 }
  56.  
  57.                 public void onStatusChanged(String provider, int status, Bundle extras) {
  58.                 }
  59.  
  60.                 public void onProviderEnabled(String provider) {
  61.                 }
  62.  
  63.                 public void onProviderDisabled(String provider) {
  64.                 }
  65.             };
  66.             gpsListener = new LocationListener() {
  67.                 public void onLocationChanged(Location location) {
  68.                     makeUseOfGPS(location);
  69.                 }
  70.  
  71.                 public void onStatusChanged(String provider, int status, Bundle extras) {
  72.                 }
  73.  
  74.                 public void onProviderEnabled(String provider) {
  75.                 }
  76.  
  77.                 public void onProviderDisabled(String provider) {
  78.                 }
  79.             };
  80.             // Kill location Listeners
  81.             locationManager.removeUpdates(networkListener);
  82.  
  83.             locationManager.removeUpdates(gpsListener);
  84.             return true;
  85.         }
  86.  
  87.         return false;
  88.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement