Here you can find the source of calcDistanceBetweenCoords(double startLat, double startLon, double endLat, double endLon)
Parameter | Description |
---|---|
startNode | Node where the way begins. |
endNode | Node where the way ends. |
public static double calcDistanceBetweenCoords(double startLat, double startLon, double endLat, double endLon)
//package com.java2s; //License from project: Open Source License public class Main { /**/* ww w. ja v a2s.c o m*/ * Calculates the distance in meter between to coordinates. The formula is * derived from "Seitencosinussatz". * * @param startNode * Node where the way begins. * @param endNode * Node where the way ends. * @return Distance in meters. */ public static double calcDistanceBetweenCoords(double startLat, double startLon, double endLat, double endLon) { if (startLat == endLat && startLon == endLon) { return 0; } return Math.acos(Math.sin(endLat / 180. * Math.PI) * Math.sin(startLat / 180. * Math.PI) + Math.cos(endLat / 180. * Math.PI) * Math.cos(startLat / 180. * Math.PI) * Math.cos(endLon / 180. * Math.PI - startLon / 180. * Math.PI)) * 6380. // ca. // der // Erdradius * 1000; // Umrechnung von km in m } }