-3

I want your help to calculate the distance b/t two longitudes. Can anybody tell me how to find the distance? I am new on Android studio. I want to find the distance in my app. Destination address in defined by mlat and mlong and current address is calculated through GPS whose value goes in longitude and latitude.

My code is:

    double mlat =30.726030;
    double mlong=76.759268;
    imgButton1 =(ImageButton)findViewById(R.id.imageButton1);
    mgButton1.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
                Location gpsLocation = appLocationService.getLocation(LocationManager.GPS_PROVIDER);
                if (gpsLocation != null) {
                     double latitude = gpsLocation.getLatitude();
                     double longitude = gpsLocation.getLongitude();    
                     String result = "Latitude: " + gpsLocation.getLatitude() +
                                    " Longitude: " + gpsLocation.getLongitude();
                     tvAddress.setText(result);
                } else {
                     showSettingsAlert();
                }
          }
   });

Tell me how to find the distance between two longitudes and latitudes.

Arnaud
  • 7,259
  • 10
  • 50
  • 71

1 Answers1

0

Use the distanceBetween method to calculate distance:

Location.distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results)
Arnaud
  • 7,259
  • 10
  • 50
  • 71
Ravi Varma
  • 43
  • 2
  • 5