Here you can find the source of distSphericalEarth(double lat1, double lon1, double lat2, double lon2)
Parameter | Description |
---|---|
lat1 | a parameter |
lon1 | a parameter |
lat2 | a parameter |
lon2 | a parameter |
public static final double distSphericalEarth(double lat1, double lon1, double lat2, double lon2)
//package com.java2s; /*/*from w ww . j a v a 2 s. c om*/ * Copyright (c) 2011 Tal Shalif * * This file is part of Talos-Rowing. * * Talos-Rowing is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Talos-Rowing 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Talos-Rowing. If not, see <http://www.gnu.org/licenses/>. */ public class Main { private static final double R = 6371; /** * calc distance between two points, using spherical earth (ignoring ellipsoidal effects) calculation. * @see http://www.movable-type.co.uk/scripts/latlong.html * @param lat1 * @param lon1 * @param lat2 * @param lon2 * @return */ public static final double distSphericalEarth(double lat1, double lon1, double lat2, double lon2) { double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double d = R * c; return d * 1000; } }