Find out the speed of the User in android Using GPS

Viewed 13123

I tried to find out the speed of User, while user is moving with device. Here, I followed one link with sample code. i.e: Here SpeedDemo.

The problem is, by using location.getSpeed() method, we are finding the speed. So, for that I changed the location values in device, but every time the value of the location.getspeed() return '0' only. Why it happen, even changing the location itself.

Can any one known about this?

3 Answers

First we need to check whether the Gps Enabled or not using location manager.

isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

Then , you need to implement GpsStatus.Listener to get the Gps updates. It will return the Gps location updates.

GPSManager.locationListener = new LocationListener() {
                    @Override
                    public void onLocationChanged(final Location location) {
                            if (GPSManager.gpsCallback != null) {
                                    GPSManager.gpsCallback.onGPSUpdate(location);
                            }
                    }

                    @Override
                    public void onProviderDisabled(final String provider) {
                    }

                    @Override
                    public void onProviderEnabled(final String provider) {
                    }

                    @Override
                    public void onStatusChanged(final String provider, final int status, final Bundle extras) {
                    }
            };

From that location you can able to get the current speed.

speed = location.getSpeed();

Refer to my website here for further details : http://velmm.com/get-current-user-speed-using-gps-android/

Related