Here you can find the source of computeDistanceInMiles(Double lat1, Double lon1, Double lat2, Double lon2)
computes the APPROXIMATE distance between 2 points (lat/lon in DEGREES, not radians) forumula described here: http://www.meridianworlddata.com/Distance-Calculation.asp
Parameter | Description |
---|---|
lat1 | a parameter |
lon1 | a parameter |
lat2 | a parameter |
lon2 | a parameter |
public static Double computeDistanceInMiles(Double lat1, Double lon1, Double lat2, Double lon2)
//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); } }