`
天梯梦
  • 浏览: 13612099 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

通过经纬度计算两地距离 calculates the distance between two points via latitude/longitude

 
阅读更多

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

 

分享到:
评论

相关推荐

    Cal_dist_two_GPS.zip_GPS data Matlab_between

    It calculates Euclidean distance between two GPS data points.

    The program calculates the binary equations

    说明: 程序计算2元方程组,采用划分网格跟搜索法计算2元方程 (The program calculates the binary equations, and the meshing and searching method is used to calculate the binary equations.)

    A星算法基本教程

    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 Au

    Internet Timer. Also calculates the cost of the call. Can AutoDetect Phone call charges from the time and date.

    sp.zip_Finish_babyxah_matlab

    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 ...

    非常优秀的PCB设计辅助工具

    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 ...

    The program calculates the binary equations.rar_The Program_stri

    程序计算2元方程组,采用划分网格跟搜索法计算2元方程

    View Factor

    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学习矢量化算法.rar_LVQ source code_LVQ-EXAMPLE_Vector Quantization_l

    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.

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    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 ...

    bentley.rar_Bentley Ottman _bentley

    calculates the bentley sweep algorithm between two trapezoidal membership functions

    The Triangle

    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 triangle

    The number of rows in the triangle is &gt; 1 but &lt;= 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 ...

    Asjusted-rand-index.zip_Adjusted Rank index_Asjusted rand index_

    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...

    kld.rar_KLD_Kullback-Leibler_distance

    This function calculates the Kullback Leibler divergence distance for Gaussians.

    RSA/ECB pbes 加密 解密

    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

    c#_C#_

    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 &amp;password two ...

    Harris corner detectd

    The code calculates the Harris Feature Points(FP)

    MarketAnalysisToolbox_update04132012.zip

    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-Plus-Plus:C ++练习和练习

    C加号C ++练习和练习。C ++ 大家好,这些示例... // ***********************************************// This program calculates the user's pay.//// By: Jesus Hilario Hernandez// Last Updated: November 21, 20

Global site tag (gtag.js) - Google Analytics