Android: Wie finde ich die mit GPS zurückgelegte Gesamtstrecke, wenn ich mich kontinuierlich bewege?

Das ist mein Code. Bitte sagen Sie mir, dass die Entfernung nicht berechnet werden kann. In diesem Coderes ist eine lange Variable, die die zurückgelegte Gesamtstrecke speichern soll. Dieser Code soll die Entfernung basierend auf GPS berechnen, sobald sich der Breiten- und Längengrad ändert.

String serviceString = Context.LOCATION_SERVICE;
LocationManager locationManager;
locationManager= (LocationManager)getSystemService(serviceString);

String provider = LocationManager.GPS_PROVIDER;
final Location loc1=locationManager.getLastKnownLocation(provider);
//Location loc1=new Location("");

String netprovider=LocationManager.NETWORK_PROVIDER;

lat1=loc1.getLatitude();
lon1=loc1.getLongitude();               

LocationListener myLocationListener = new LocationListener() 
                        {
                            public void onLocationChanged(Location loc1) 
                            {

                            Location loc2=new Location("");
                            lat2=loc2.getLatitude();
                            lon2=loc2.getLongitude();
                            dtvalue.setText(lat1+","+lon1+","+lat2+","+lon2);

                            Location.distanceBetween(lat1,lon1,lat2,lon2,dist);
                            res=res+(long)dist[0];

                            lat1=lat2;
                            lon1=lon2;
                        }
                        public void onProviderDisabled(String provider)
                        {
                            // Update application if provider disabled.
                        }
                        public void onProviderEnabled(String provider)
                        {
                            // Update application if provider enabled.
                        }
                        public void onStatusChanged(String provider, int status,
                                Bundle extras)
                        {
                            // Update application if provider hardware status changed.
                        }
                    };
locationManager.requestLocationUpdates(provider, 5000, 1, myLocationListener);
locationManager.requestLocationUpdates(netprovider, 5000, 1, myLocationListener);

Antworten auf die Frage(1)

Ihre Antwort auf die Frage