I have been trying to get speed by the help of GPS. I would like to get Gps datas(latitude-longitude-speed) when my telephone fell down.
When telephone fell down, gps datas are obtained and sent to my server. For this aim, I used threads. Each thread get gps datas and send to server them.
My problem is speed value. I got speed calculating distance between two location and time (speed = distance / time)
Thread makes :
@Override
public void run() {
    Looper.prepare();
    float distance = 0.0f;
    float[] results = new float[1];
    Long longValue = new Long(11);
    double firstLatitude;
    double firstLongitude;
    long firstTime;
    float speedOfDevice = 0.0f;
    //for sendin gps datas to web server
    ReportLocation reportObj = new ReportLocation(this);
    locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
    //latitude, longitude and timeOffix is set in location listener
    firstLatitude = latitude;
    firstLongitude = longitude;
    firstTime = timeOfFix;
    // Waiting 1.5 second 
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
        Toast.makeText(this, "Sleep exception", Toast.LENGTH_LONG).show();
    }
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
    if( timeOfFix != firstTime ) {
        Location.distanceBetween(firstLatitude, firstLongitude, latitude, longitude, results);
        distance = results[0];
        longValue = new Long(timeOfFix - firstTime );
        speedOfDevice = 3600 * distance / ( longValue.floatValue() ); 
    }
    try {
        reportObj.send( Double.toString(firstLatitude),  Double.toString(firstLongitude), Float.toString( speedOfDevice ) );
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        Toast.makeText(this, "Client protokol exception ", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Toast.makeText(this, "IO exception "+e.getMessage(), Toast.LENGTH_LONG).show();
    }
    handler.sendEmptyMessage(0);
    Looper.loop();
}
}
class MyLocationListener implements LocationListener {
    @Override
    public void onLocationChanged(Location location) {
        if (location != null) {
            locManager.removeUpdates(locListener); 
            latitude = location.getLatitude();
            longitude = location.getLongitude();
            timeOfFix = location.getTime();
        }  
    }
    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub
    }
}
I tried my program in the car that in motion. But I couldn't get correct speed datas.. For example 7.31365 , 8.29663 etc.. They should be 50- 60 or 70 km/h..
What are your thoughts ?
 
     
    