GPS - Get distance, time while running and walking

I have a situation where I need to use a GPS technique.

I need to find the distance between two points when a person is walking.

When the person starts to walk, he will Start button

click on , and when he stops, he will clickstop button

after that he must show him

1. time 2. Travel to Kms. 3.from place where (place name), for example: a to b

Do I need to have google maps for this?

I saw the code here to get the current location which gives me the latitude longitude.

please help how to do this

**

Edited:

**

This is the code I am using

private EditText editTextShowLocation;
    private Button buttonGetLocation;
    private ProgressBar progress;

    private LocationManager locManager;
    private LocationListener locListener = new MyLocationListener();

    private boolean gps_enabled = false;
    private boolean network_enabled = false;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        editTextShowLocation = (EditText) findViewById(R.id.editTextShowLocation);

        progress = (ProgressBar) findViewById(R.id.progressBar1);
        progress.setVisibility(View.GONE);

        buttonGetLocation = (Button) findViewById(R.id.buttonGetLocation);
        buttonGetLocation.setOnClickListener(this);

        locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    }

    @Override
    public void onClick(View v) {
        progress.setVisibility(View.VISIBLE);
        // exceptions will be thrown if provider is not permitted.
        try {
            gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        } catch (Exception ex) {
        }
        try {
            network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        } catch (Exception ex) {
        }

        // don't start listeners if no provider is enabled
        if (!gps_enabled && !network_enabled) {
            AlertDialog.Builder builder = new Builder(this);
            builder.setTitle("Attention!");
            builder.setMessage("Sorry, location is not determined. Please enable location providers");
            builder.setPositiveButton("OK", this);
            builder.setNeutralButton("Cancel", this);
            builder.create().show();
            progress.setVisibility(View.GONE);
        }

        if (gps_enabled) {
            locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
        }
        if (network_enabled) {
            locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locListener);
        }
    }

    class MyLocationListener implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                // This needs to stop getting the location data and save the battery power.
                locManager.removeUpdates(locListener); 

                String londitude = "Londitude: " + location.getLongitude();
                String latitude = "Latitude: " + location.getLatitude();
                String altitiude = "Altitiude: " + location.getAltitude();
                String accuracy = "Accuracy: " + location.getAccuracy();
                String time = "Time: " + location.getTime();

                editTextShowLocation.setText(londitude + "\n" + latitude + "\n" + altitiude + "\n" + accuracy + "\n" + time);
                progress.setVisibility(View.GONE);
            } 
        }

        @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

        }
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        if(which == DialogInterface.BUTTON_NEUTRAL){
            editTextShowLocation.setText("Sorry, location is not determined. To fix this please enable location providers");
        }else if (which == DialogInterface.BUTTON_POSITIVE) {
            startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
        }
    }

      

Shows the Logarithm of the Logarithm that I enter from emulator control.

In this I manually enter the longitude and latitude details by going to window->showview->other->emulator control

for testing in the emulator, but I need to have two edittext where I enter the name of the place (A) and (B)

he must give me distance

please, help

+3


source to share


5 answers


try using Google Api Distance Matrix



https://developers.google.com/maps/documentation/distancematrix/

+2


source


You can find out the distance between two points (in terms of latitude and longitude) using Spherical Trigonometry

You have to use simple date objects and compare startTime and endTime.

(OR)



You can get approximate distance using below code

double distance;  

Location locationA = new Location("point A");  

locationA.setLatitude(latA);  
locationA.setLongitude(lngA);  

Location locationB = new Location("point B");  

locationB.setLatitude(latB);  
LocationB.setLongitude(lngB);  

distance = locationA.distanceTo(locationB); 

      

0


source


You can use currentTimeinMillis () to get the start and end times of your trip.

Then you can use the formulas given here to find the distance, and finally you have to use a reverse geocoding service like Nominatim to be able to get the address of the place from your GPS coordinates.

That being said, the distance formula will give you the distance between one point and the next, not the actual offset. If this is not what you want, but you want the actual distance traveled, you will need to calculate this value in a shorter amount of time.

0


source


I suppose the question is one of the walking.

Do you walk the streets or like a crow flies?

If on the streets and connected to the web, use google api .. It calculates routing based on two points and returns XML. Should be easy enough to figure out.

If he flies ... well then just (a * a) + (b * b) = (c * c) it's much easier .. You could direct your user to big turns. Or you could run a runnable every 10 seconds after they hit start and draw dots. Still a * a + b * b = c * c, but just a few steps.

You will of course have to run it on a service. And given the choice, I would go with that option. You can adjust the cycle time based on the speed traveled. There will be fewer pauses faster. It requires less on your dataplan.


EDIT
Ah .. I see what you are looking for. This is not what I thought you asked for. Simplify .. convert lat / long to GPS. and then do some simple math on the last saved point
void addDistance()
{
  newX = ...
  newY = ...
  deltaX = absolute(m_oldX - newX)
  deltaY = absolute(m_oldY = newY)
  m_distance += sqrt(deltaX^2 + deltaY^2);
  m_oldX = newX;
  m_oldY = newY;
}
void startOver()
{
  newX = ...
  newY = ...
  m_distance = 0;
  m_oldX = newX;
  m_oldY = newY;

}

      

0


source


To get the distance between two points (A to B), android has a function called distanceTo .

For example, double distance = startLocation.distanceTo (finishLocation) / 1000;

During the time npinti said you can use currentTimeinMillis (), or you can also use a Timer and show it to the user when he hits the start button. Its just like a stopwatch.

Edited

Location A - New York

Place B - Paris

In this case, you first need to convert the string to Location (that is, you need latitude and longitude). To do this, you use the concept of geocoding.

List<Address> foundGeocode = null;
foundGeocode = new Geocoder(this).getFromLocationName("address here", 1);
 foundGeocode.get(0).getLatitude(); //getting latitude
 foundGeocode.get(0).getLongitude();//getting longitude

      

After that, you can calculate the distance from the DistanceTo method. Hope this helps ....

0


source







All Articles