public static double distance(double lat1,double lat2,double lon1,double lon2,double el1,double el2){
  final int R=6371;
  Double latDistance=deg2rad(lat2 - lat1);
  Double lonDistance=deg2rad(lon2 - lon1);
  Double a=Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(lonDistance / 2)* Math.sin(lonDistance / 2);
  Double c=2 * Math.atan2(Math.sqrt(a),Math.sqrt(1 - a));
  double distance=R * c * 1000;
  double height=el1 - el2;
  distance=Math.pow(distance,2) + Math.pow(height,2);
  return Math.sqrt(distance);
}

public static double distance ( double lat1 , double lat2 , double lon1 , double lon2 , double el1 , double el2 ) { final int R = 6371 ; Double latDistance = deg2rad ( lat2 - lat1 ) ; Double lonDistance = deg2rad ( lon2 - lon1 ) ; Double a = Math . sin ( latDistance / 2 ) * Math . sin ( latDistance / 2 ) + Math . cos ( deg2rad ( lat1 ) ) * Math . cos ( deg2rad ( lat2 ) ) * Math . sin ( lonDistance / 2 ) * Math . sin ( lonDistance / 2 ) ; Double c = 2 * Math . atan2 ( Math . sqrt ( a ) , Math . sqrt ( 1 - a ) ) ; double distance = R * c * 1000 ; double height = el1 - el2 ; distance = Math . pow ( distance , 2 ) + Math . pow ( height , 2 ) ; return Math . sqrt ( distance ) ; }
calculate distance between two points in latitude and longitude taking into account height difference . if you are not interested in height difference pass 0 . 0 . uses haversine method as its base . < p / > lat1 , lon1 start point lat2 , lon2 end point el1 start altitude in meters el2 end altitude in meters
