Android Distance Calculate distanceBetweenTwoLatLongs(Location oldLocation, Location newLocation)

Here you can find the source of distanceBetweenTwoLatLongs(Location oldLocation, Location newLocation)

Description

distance Between Two Lat Longs

Declaration

public static double distanceBetweenTwoLatLongs(Location oldLocation,
            Location newLocation) 

Method Source Code

//package com.java2s;

import android.location.Location;

import android.util.Log;

public class Main {
    public static double distanceBetweenTwoLatLongs(Location oldLocation,
            Location newLocation) {
        double distance = 0;
        if (newLocation != null && oldLocation != null) {
            distance = oldLocation.distanceTo(newLocation); // in meters
        } else {//from   ww w.j a v  a  2 s.c  om
            if (newLocation == null) {
                Log.e("newLocation is null", ";;");
            }
            if (oldLocation == null) {
                Log.e("oldLocation is null", ";;");
            }
        }
        Log.e("distanceBetweenTwoLatLongs", "" + distance / 1000);
        return distance / 1000; // Convert meters to KM
    }
}

Related

  1. getDistance(double lat1, double lon1, double lat2, double lon2)
  2. dist(PointF p1, PointF p2)
  3. distance(int q1, int r1, int q2, int r2)
  4. distanceInMeters(float distance)
  5. distanceBetweenTwoPoints(double lat1, double lng1, double lat2, double lng2)
  6. KmToMiles(int distance)
  7. getTempsTrajetBus(int distance)