Java Distance Calculate computeDistanceInMiles(Double lat1, Double lon1, Double lat2, Double lon2)

Here you can find the source of computeDistanceInMiles(Double lat1, Double lon1, Double lat2, Double lon2)

Description

computes the APPROXIMATE distance between 2 points (lat/lon in DEGREES, not radians) forumula described here: http://www.meridianworlddata.com/Distance-Calculation.asp

License

Open Source License

Parameter

Parameter Description
lat1 a parameter
lon1 a parameter
lat2 a parameter
lon2 a parameter

Declaration

public static Double computeDistanceInMiles(Double lat1, Double lon1, Double lat2, Double lon2) 

Method Source Code

//package com.java2s;
/*//from   w w  w .jav a2  s. c o m
 *  Copyright (C) 2010-2012 Stichting Akvo (Akvo Foundation)
 *
 *  This file is part of Akvo FLOW.
 *
 *  Akvo FLOW is free software: you can redistribute it and modify it under the terms of
 *  the GNU Affero General Public License (AGPL) as published by the Free Software Foundation,
 *  either version 3 of the License or any later version.
 *
 *  Akvo FLOW is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Affero General Public License included below for more details.
 *
 *  The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>.
 */

public class Main {
    /**
     * computes the APPROXIMATE distance between 2 points (lat/lon in DEGREES, not radians) forumula
     * described here: http://www.meridianworlddata.com/Distance-Calculation.asp
     * 
     * @param lat1
     * @param lon1
     * @param lat2
     * @param lon2
     * @return
     */
    public static Double computeDistanceInMiles(Double lat1, Double lon1, Double lat2, Double lon2) {
        double x = 69.1 * (lat2 - lat1);
        double y = 53.0 * (lon2 - lon1) * Math.cos(lat1 / 57.3);
        return Math.sqrt(x * x + y * y);
    }
}

Related

  1. computeDistance(final int[] position1, final int[] position2)
  2. computeDistance(int p1x, int p1y, int p2x, int p2y)
  3. computeDistance(long[] a, long[] b)
  4. computeDistanceAndBearingFast(double lat1, double lon1, double lat2, double lon2, float[] results)
  5. computeDistanceImpl(final String firstStringInAlgorithm, final String secondStringInAlgorithm)
  6. computeDistanceMap(int[][] image)
  7. computeDistanceSqr(double t, double b1, double b2, double b3, double b4, double b5, double b6)
  8. computeDistanceUsingRadians(double lat1Radians, double lng1Radians, double lat2Radians, double lng2Radians)
  9. dist(double lat1, double long1, double lat2, double long2)