3

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;
    }
}
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
  • Here's a closed off-topic http://stackoverflow.com/questions/1567443/how-accurate-is-android-gps which have a good amount of information on the GPS accuracy – denis.solonenko Mar 27 '13 at 05:19
  • sir if we use gps co-ordinates for tracking vehicles live in google map ....how we know whether the vehicle is at a stop position –  Mar 27 '13 at 05:25
  • well, short answer - we actually don't :) using gps coordinates we can only approximate the location with appropriate accuracy.. – denis.solonenko Mar 27 '13 at 05:30
  • Have you computed the distance between those lat/longs? If you are tracking vehicles, within a few seconds, the difference between lat/longs are probably at least over a few meters. – dannyroa Mar 27 '13 at 05:30

2 Answers2

2

GPS isn't exact. With the hardware in a common phone, it can be up to about 10 meters or so off at any time. So multiple readings in a row will not have the same exact location.

Network provider is even worse- it can have up to 1km of inaccuracy.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • actually i'm using these gps co-ordinates for tracking vehicle....so how can we know whether the vehicle stops or not .....example if we get the same latitude and longitude for a given point for a certain amt of time...we can say that the vehicle is at stop.... –  Mar 27 '13 at 05:19
  • Good luck. I just spent several weeks tweaking that type of algorithm for an app I wrote (you can find it via my website), and you'll never get a 100% answer. You're going to come up with a heuristic at best. But yes, you're going to have to set up speed thresholds. Then it gets fun if you add in the fact the guy can leave the car with the phone in his pocket and he'd still be moving. Or stopped in traffic and not move at all for a few minutes... – Gabe Sechan Mar 27 '13 at 05:25
  • sir how about calculating the distance between two co-ordinates....through that we can find whether that guy is at constant or moving.... –  Mar 27 '13 at 05:37
  • That I can help on. The location object has a distance function. It will figure out the distance between points in meters. – Gabe Sechan Mar 27 '13 at 05:46
0

The coordinates do not point to the same location, if you zoom in enough you see that they differ by some meters.
to detect stand still on one location you either can calculate the distance to the last position, and only when it exceeds a threshold you use the location, or you use the speed attribute of the GPS location.

AlexWien
  • 28,470
  • 6
  • 53
  • 83
  • so wat's the solution to find if the person with the device is remaining constant without any movement at one point....example the person with the device in vehicle stops at a location and remains there for a time being –  Mar 27 '13 at 17:44
  • You can use both solutions: distance to last good position, or speed < x km/h as indicator – AlexWien Mar 27 '13 at 18:26