Javascript版:
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //::: ::: //::: This routine calculates the distance between two points (given the ::: //::: latitude/longitude of those points). It is being used to calculate ::: //::: the distance between two locations using GeoDataSource (TM) prodducts ::: //::: ::: //::: Definitions: ::: //::: South latitudes are negative, east longitudes are positive ::: //::: ::: //::: Passed to function: ::: //::: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) ::: //::: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) ::: //::: unit = the unit you desire for results ::: //::: where: 'M' is statute miles (default) ::: //::: 'K' is kilometers ::: //::: 'N' is nautical miles ::: //::: ::: //::: Worldwide cities and other features databases with latitude longitude ::: //::: are available at http://www.geodatasource.com ::: //::: ::: //::: For enquiries, please contact sales@geodatasource.com ::: //::: ::: //::: Official Web site: http://www.geodatasource.com ::: //::: ::: //::: GeoDataSource.com (C) All Rights Reserved 2015 ::: //::: ::: //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: function distance(lat1, lon1, lat2, lon2, unit) { var radlat1 = Math.PI * lat1/180 var radlat2 = Math.PI * lat2/180 var radlon1 = Math.PI * lon1/180 var radlon2 = Math.PI * lon2/180 var theta = lon1-lon2 var radtheta = Math.PI * theta/180 var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta); dist = Math.acos(dist) dist = dist * 180/Math.PI dist = dist * 60 * 1.1515 if (unit=="K") { dist = dist * 1.609344 } if (unit=="N") { dist = dist * 0.8684 } return dist }
php版:
<?php /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ /*:: :*/ /*:: This routine calculates the distance between two points (given the :*/ /*:: latitude/longitude of those points). It is being used to calculate :*/ /*:: the distance between two locations using GeoDataSource(TM) Products :*/ /*:: :*/ /*:: Definitions: :*/ /*:: South latitudes are negative, east longitudes are positive :*/ /*:: :*/ /*:: Passed to function: :*/ /*:: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :*/ /*:: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :*/ /*:: unit = the unit you desire for results :*/ /*:: where: 'M' is statute miles (default) :*/ /*:: 'K' is kilometers :*/ /*:: 'N' is nautical miles :*/ /*:: Worldwide cities and other features databases with latitude longitude :*/ /*:: are available at http://www.geodatasource.com :*/ /*:: :*/ /*:: For enquiries, please contact sales@geodatasource.com :*/ /*:: :*/ /*:: Official Web site: http://www.geodatasource.com :*/ /*:: :*/ /*:: GeoDataSource.com (C) All Rights Reserved 2015 :*/ /*:: :*/ /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } echo distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles<br>"; echo distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers<br>"; echo distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles<br>"; ?>
原文:通过经纬度计算两地距离 calculates the distance between two points via latitude/longitude
相关推荐
It calculates Euclidean distance between two GPS data points.
说明: 程序计算2元方程组,采用划分网格跟搜索法计算2元方程 (The program calculates the binary equations, and the meshing and searching method is used to calculate the binary equations.)
distance.m : This is a function that calculates the distance between 2 nodes. min_fn.m : This function takes the list OPEN as one of its arguments and returns the node with the smallest cost ...
Internet Timer. Also calculates the cost of the call. Can AutoDetect Phone call charges from the time and date.
Dijkstra%DIJKSTRA Calculates the shortest distance and path between points on a map % using Dijkstra's Shortest Path Algorithm % % [DIST, PATH] = DIJKSTRA(NODES, SEGMENTS, SID, FID) % Calculates the ...
Calculates the current a via needs to raise its temperature over ambient per IPC-2152. Other via properties include: Via capacitance Via inductance Via impedance Via step response Via DC resistance ...
程序计算2元方程组,采用划分网格跟搜索法计算2元方程
Another model implemented, calculates the view factor between two or more surfaces. Determination of the long-wave radiant heat exchange between two or more surfaces or heat exchange with a surface ...
LVQ学习矢量化算法源程序 This directory contains code implementing...each neuron is identified and the Euclidean distance between the pattern and each neuron is reported. Output is directed to the screen.
on a curve by the distance from the original point on the perimeter. - ADD: Added the method TCustomProp.GetPublishedComplexProp - returns included complex flex-property by name registered through ...
calculates the bentley sweep algorithm between two trapezoidal membership functions
Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally ...
The number of rows in the triangle is > 1 but <= 100. The numbers in the triangle, all integers, are between 0 and 99. Output Your program is to write to standard output. The highest sum is written ...
This Matlab code calculates the Rand Index and Adjusted rand Index between two clustering groups. The two input clusters has to be in the form of a structure as shown in the example mat file ( A and B...
This function calculates the Kullback Leibler divergence distance for Gaussians.
So, the program is able to verifier will detect the attack of Adversary, which is placed in between Sender and Verifier and may change either the original message, or encrypted digest, or both
My Project is about an OnlineCompetition Written in VisualPrograming (C#) by using Windows formnanof my project .It content five formForm1 tools: two textbox to enter the username &password two ...
The code calculates the Harris Feature Points(FP)
The Huff Model is a spatial interaction model that calculates gravity-based probabilities of consumers at each origin location patronizing each store in the store dataset. From these probabilities, ...
C加号C ++练习和练习。C ++ 大家好,这些示例... // ***********************************************// This program calculates the user's pay.//// By: Jesus Hilario Hernandez// Last Updated: November 21, 20