title: create android tracking apps in eclipse
body: <p>hei i am create an android car tracking apps for my final test but when i test my tracking apps its keep sending same coordinates to my database here is my gpstracking code</p>
  
  <pre><code>    package com.example.id.library;
  
      import android.app.AlertDialog;
      import android.app.Service;
      import android.content.Context;
      import android.content.DialogInterface;
      import android.content.Intent;
      import android.location.Location;
      import android.location.LocationListener;
      import android.location.LocationManager; 
      import android.os.Bundle;
      import android.os.IBinder;
      import android.provider.Settings;
      import android.util.Log;
  
      public class gps extends Service implements LocationListener {
  
      private final Context mContext;
  
      // flag buat status gps. on atau nda
      boolean isGPSEnabled = false;
  
      // flag buat network.
      boolean isNetworkEnabled = false;
  
      // flag buat posisi gps. bisa dapat koordinat atau nda
      boolean canGetLocation = false;
  
      Location location; // variabel untuk lokasi
      double latitude; // latitudenya
      double longitude; // longitudenya
  
      // minimum perbedaan jarak untuk update
      private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meter
  
      // minimum selang waktu tiap update lokasi
      private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 menit
  
      // deklarasi Location Manager
      protected LocationManager locationManager;
  
      public gps(Context context) {
          this.mContext = context;
          getLocation();
      }
  
      public Location getLocation() {
          try {
              locationManager = (LocationManager) mContext
                      .getSystemService(LOCATION_SERVICE);
  
              // tarik status gps
              isGPSEnabled = locationManager
                      .isProviderEnabled(LocationManager.GPS_PROVIDER);
  
              // tarik status network
              isNetworkEnabled = locationManager
                      .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  
              if (!isGPSEnabled &amp;&amp; !isNetworkEnabled) {
                  // kalo semua GPS dan Network mati
                  // buka alert untuk enable gps
              } else { // kalo GPS atau network bisa dapat lokasi
                  this.canGetLocation = true;
                  // ambil lokasi dari network dulu
                  if (isNetworkEnabled) {
                      locationManager.requestLocationUpdates(
                              LocationManager.NETWORK_PROVIDER,
                              MIN_TIME_BW_UPDATES,
                              MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                      Log.d("Network", "Network");
                      if (locationManager != null) {
                          location = locationManager
                                  .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                          if (location != null) {
                              latitude = location.getLatitude();
                              longitude = location.getLongitude();
                          }
                      }
                  }
                  // kalo GPS ON, ambil koordinat yang lebih presisi
                  if (isGPSEnabled) {
                      if (location == null) {
                          locationManager.requestLocationUpdates(
                                  LocationManager.GPS_PROVIDER,
                                  MIN_TIME_BW_UPDATES,
                                  MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                          Log.d("GPS Enabled", "GPS Enabled");
                          if (locationManager != null) {
                              location = locationManager
                                      .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                              if (location != null) {
                                  latitude = location.getLatitude();
                                  longitude = location.getLongitude();
                              }
                          }
                      }
                  }
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          return location;
      }
  
      // fungsi untuk stop listener GPS
      public void stopUsingGPS() {
          if (locationManager != null) {
              locationManager.removeUpdates(gps.this);
          }
      }
  
      // fungsi untuk ambil latitude
      public double getLatitude() {
          if (location != null) {
              latitude = location.getLatitude();
          }
  
          // return nilai latitude
          return latitude;
      }
  
      // fungsi untuk ambil longitude
      public double getLongitude() {
          if (location != null) {
              longitude = location.getLongitude();
          }
  
          // return nilai longitude
          return longitude;
      }
  
      // fungsi untuk cek gps bisa ambil koordinat atau nda
      public boolean canGetLocation() {
          return this.canGetLocation;
      }
  
      // fungsi untuk alert dialog kalau GPS mati
      public void showSettingsAlert() {
          AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
  
          // title
          alertDialog.setTitle("Loading GPS");
  
          // Dialog
          alertDialog
                  .setMessage("GPS dalam kondisi mati. Silakan nyalakan GPS terlebih dahulu.");
  
          // tombol setting
          alertDialog.setPositiveButton("Settings",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          Intent intent = new Intent(
                                  Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                          mContext.startActivity(intent);
                      }
                  });
  
          // tombol cancel
          alertDialog.setNegativeButton("Cancel",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          dialog.cancel();
                      }
                  });
  
          // tampilkan alert
          alertDialog.show();
      }
  
      @Override
      public void onLocationChanged(Location location) {
      }
  
      @Override
      public void onProviderDisabled(String provider) {
      }
  
      @Override
      public void onProviderEnabled(String provider) {
      }
  
      @Override
      public void onStatusChanged(String provider, int status, Bundle extras) {
      }
  
      @Override
      public IBinder onBind(Intent arg0) {
          return null;
      }
  
  }
  </code></pre>
  
  <p>and here what my cordinates that my gpsracking send to my database</p>
  
  <p><a href="https://i.stack.imgur.com/PYsOl.png" rel="nofollow noreferrer">like u see my apps keep sending the same cordinates and i swear i have already walk for more than 1 kilometers</a></p>
  
  <p>pls someone  help me and sorry for my bad english </p>
  
  <p><a href="https://i.stack.imgur.com/PYsOl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PYsOl.png" alt="enter image description here"></a></p>