I've created an android application to get the latitude and longitude of the location every 2 seconds. The application works fine but when i keep my android device constant at one location i'm getting different latitude and longitude for that point... surprisingly even all those different co-ordinates points to the same location even if they are different.
for example for a constant location
i'm getting like
Latitude - 10.013499
Longitude - 76.3303451
after 2 seconds
Latitude - 10.0135014
Longitude - 76.3303467
after 2 seconds
Latitude - 10.0135001
Longitude - 76.3303451
after 2 seconds
Latitude - 10.0135011
Longitude - 76.3303466
can anyone please tell me why i'm getting like this..
how can we get a unique latitude and longitude for a given point.
my code is given below
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class AndroidGPSTrackingActivity extends Activity {
Button btnShowLocation, stop;
double latitude, longitude;
int is = 0;
ScheduledExecutorService scheduler;
// GPSTracker class
GPSTracker gps;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
stop = (Button) findViewById(R.id.stop);
// show location button click event
btnShowLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// create class object
scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
System.out.println("sss");
// Log.i("hello", "world");
is++;
Log.i("hello", "" + is);
runOnUiThread(new Runnable() {
public void run() {
gps = new GPSTracker(
AndroidGPSTrackingActivity.this);
latitude = gps.getLatitude();
longitude = gps.getLongitude();
Toast.makeText(
getApplicationContext(),
"Your Location is - \nLat: " + latitude
+ "\nLong: " + longitude,
Toast.LENGTH_SHORT).show();
}
});
}
}, 2, 2, TimeUnit.SECONDS);
}
});
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
scheduler.shutdown();
onDestroy();
}
});
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service destroyed...", Toast.LENGTH_LONG).show();
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
}