Here you can find the source of computeDistanceAndBearingFast(double lat1, double lon1, double lat2, double lon2, float[] results)
Parameter | Description |
---|---|
lat1 | a parameter |
lon1 | a parameter |
lat2 | a parameter |
lon2 | a parameter |
results | a parameter |
private static void computeDistanceAndBearingFast(double lat1, double lon1, double lat2, double lon2, float[] results)
//package com.java2s; /* //from w w w . java 2s. c o m * Copyright (C) 2014 team-cachebox.de * * Licensed under the : GNU General Public License (GPL); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.gnu.org/licenses/gpl.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * precalculation of Math.PI / 180.0 */ static public final double DEG_RAD = Math.PI / 180.0; /** * WGS84 major axis = 6378137.0 */ static public final double WGS84_MAJOR_AXIS = 6378137.0; /** * Fast calculation with Cos/Sin/Atan over LockUpTable * * @param lat1 * @param lon1 * @param lat2 * @param lon2 * @param results */ private static void computeDistanceAndBearingFast(double lat1, double lon1, double lat2, double lon2, float[] results) { double longitude1 = lon1; double longitude2 = lon2; double latitude1 = Math.toRadians(lat1); double latitude2 = Math.toRadians(lat2); lat1 *= DEG_RAD; lon1 *= DEG_RAD; lat2 *= DEG_RAD; lon2 *= DEG_RAD; int IntWGS84_MAJOR_AXIS = (int) WGS84_MAJOR_AXIS; results[0] = (float) ((IntWGS84_MAJOR_AXIS) * Math .acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos((lon2 - lon1)))); // results[0] = (float) Distance; if (results.length > 1) { double longDiff = Math.toRadians(longitude2 - longitude1); double y = Math.sin(longDiff) * Math.cos(latitude2); double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff); double angle = Math.toDegrees(Math.atan2(y, x)); results[1] = (float) (angle); if (results.length > 2) { results[2] = results[1]; } } } }