document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. GPSTracker.java
  2. public Location getLocation() {
  3.         try {
  4.             locationManager = (LocationManager) mContext
  5.                     .getSystemService(LOCATION_SERVICE);
  6.  
  7.             // getting GPS status
  8.             isGPSEnabled = locationManager
  9.                     .isProviderEnabled(LocationManager.GPS_PROVIDER);
  10.  
  11.             // getting network status
  12.             isNetworkEnabled = locationManager
  13.                     .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  14.  
  15.             if (!isGPSEnabled && !isNetworkEnabled) {
  16.                 // no network provider is enabled
  17.             } else {
  18.                 this.canGetLocation = true;
  19.                 // First get location from Network Provider
  20.                 if (isNetworkEnabled) {
  21.                     locationManager.requestLocationUpdates(
  22.                             LocationManager.NETWORK_PROVIDER,
  23.                             MIN_TIME_BW_UPDATES,
  24.                             MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
  25.                     Log.d("Network", "Network");
  26.                     if (locationManager != null) {
  27.                         location = locationManager
  28.                                 .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
  29.                         if (location != null) {
  30.                             latitude = location.getLatitude();
  31.                             longitude = location.getLongitude();
  32.                         }
  33.                     }
  34.                 }
  35.                 // if GPS Enabled get lat/long using GPS Services
  36.                 if (isGPSEnabled) {
  37.                     if (location == null) {
  38.                         locationManager.requestLocationUpdates(
  39.                                 LocationManager.GPS_PROVIDER,
  40.                                 MIN_TIME_BW_UPDATES,
  41.                                 MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
  42.                         Log.d("GPS Enabled", "GPS Enabled");
  43.                         if (locationManager != null) {
  44.                             location = locationManager
  45.                                     .getLastKnownLocation(LocationManager.GPS_PROVIDER);
  46.                             if (location != null) {
  47.                                 latitude = location.getLatitude();
  48.                                 longitude = location.getLongitude();
  49.                             }
  50.                         }
  51.                     }
  52.                 }
  53.             }
  54.  
  55.         } catch (Exception e) {
  56.             e.printStackTrace();
  57.         }
  58.  
  59.         return location;
  60.     }
  61.     @Override
  62.     public void onLocationChanged(Location location) {
  63.     }
  64.  
  65.     @Override
  66.     public void onProviderDisabled(String provider) {
  67.     }
  68.  
  69.     @Override
  70.     public void onProviderEnabled(String provider) {
  71.     }
  72.  
  73.     @Override
  74.     public void onStatusChanged(String provider, int status, Bundle extras) {
  75.     }
  76.  
  77.     @Override
  78.     public IBinder onBind(Intent arg0) {
  79.         return null;
  80.     }
');