Java implementa el cálculo de la distancia entre dos puntos de latitud y longitud, y cargue directamente el código.
La copia del código es la siguiente:
paquete com.jttx.poi.utils;
import com.jttx.poi.entity.point;
/**
* Creado por Louis en 2014/9/2.
*/
Geoutils de clase pública {
/**
* Calcule la distancia entre dos puntos de latitud y longitud (unidad: metros)
* @param lng1 longitud
* @param lat1 latitud
* @param lng2
* @param lat2
* @devolver
*/
Public static doble getDistance (doble LNG1, doble LAT1, doble LNG2, doble LAT2) {
doble radlat1 = math.toradians (LAT1);
doble radlat2 = math.toradians (lat2);
doble a = radlat1 - radlat2;
doble b = matemáticas. Toradianos (LNG1) - Math.toradians (LNG2);
Doble S = 2 * Math.asin (Math.Sqrt (Math.Pow (Math.sin (A / 2), 2) + Math.Cos (Radlat1)
* Math.Cos (Radlat2) * Math.Pow (Math.sin (b / 2), 2)));
S = S * 6378137.0; // Tome el radio de la longitud de la Tierra en el elipsoide de referencia estándar WGS84 (Unidad: M)
S = Math.round (S * 10000) / 10000;
regreso s;
}
/**
* Calcule el valor de TP
* @param Curpoint Current Point
* @Param RelationPoint Offset Point
* @param isGeography si las coordenadas geográficas son falsas son coordenadas 2D
* @return tp valor
*/
Public static double getDirangle (Point Curpoint, Point RelatedPoint, boolean isGeography) {
resultado doble = 0;
if (isGeography) {
doble y2 = math.toradians (RelationPoint.getLat ());
doble y1 = math.toradians (curpoint.getLat ());
Double alfa = Math.atan2 (RelationPoint.getLat () - Curpoint.getLat (), (RelationPoint.getLng () - CurPoint.getLng ()) * Math.Cos ((Y2 - Y1)/ 2)); // Latitud Dirección multiplicada por COS (Y2-Y1/2)
doble delta = alfa <0? (2*Math.pi+alfa): alfa;
resultado = Math.TodeGrees (delta);
}demás {
doble alfa = Math.atan2 (RelationPoint.getLat () - Curpoint.getLat (), RelationPoint.getLng () - CurPoint.getLng ());
doble delta = alfa <0? (2*math.pi+alfa): alfa;
resultado = Math.TodeGrees (delta);
}
resultado de retorno;
}
public static void main (string [] args) {
System.out.println (GetDistance (121.446014, 31.215937, 121.446028464238, 31.2158502442799);
}
}
Lo anterior se trata de este artículo, espero que les guste.