distance between two locations in php

Solutions on MaxInterview for distance between two locations in php by the best coders in the world

showing results for - "distance between two locations in php"
Willis
08 Jun 2018
1<?php
2
3/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
4/*::                                                                         :*/
5/*::  This routine calculates the distance between two points (given the     :*/
6/*::  latitude/longitude of those points). It is being used to calculate     :*/
7/*::  the distance between two locations using GeoDataSource(TM) Products    :*/
8/*::                                                                         :*/
9/*::  Definitions:                                                           :*/
10/*::    South latitudes are negative, east longitudes are positive           :*/
11/*::                                                                         :*/
12/*::  Passed to function:                                                    :*/
13/*::    lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees)  :*/
14/*::    lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees)  :*/
15/*::    unit = the unit you desire for results                               :*/
16/*::           where: 'M' is statute miles (default)                         :*/
17/*::                  'K' is kilometers                                      :*/
18/*::                  'N' is nautical miles                                  :*/
19/*::  Worldwide cities and other features databases with latitude longitude  :*/
20/*::  are available at https://www.geodatasource.com                          :*/
21/*::                                                                         :*/
22/*::  For enquiries, please contact sales@geodatasource.com                  :*/
23/*::                                                                         :*/
24/*::  Official Web site: https://www.geodatasource.com                        :*/
25/*::                                                                         :*/
26/*::         GeoDataSource.com (C) All Rights Reserved 2018                  :*/
27/*::                                                                         :*/
28/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
29function distance($lat1, $lon1, $lat2, $lon2, $unit) {
30  if (($lat1 == $lat2) && ($lon1 == $lon2)) {
31    return 0;
32  }
33  else {
34    $theta = $lon1 - $lon2;
35    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
36    $dist = acos($dist);
37    $dist = rad2deg($dist);
38    $miles = $dist * 60 * 1.1515;
39    $unit = strtoupper($unit);
40
41    if ($unit == "K") {
42      return ($miles * 1.609344);
43    } else if ($unit == "N") {
44      return ($miles * 0.8684);
45    } else {
46      return $miles;
47    }
48  }
49}
50
51echo distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles<br>";
52echo distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers<br>";
53echo distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles<br>";
54
55?>
Karl
17 Oct 2017
1panipat
queries leading to this page
php function for calculating distance bewteen 2 locationscalculate distance between two points latitude longitude phpfind distance between two coordinates phplatitude 2flongitude distance calculator in phpcalculate arrival time between two latitude and longtitude in phpcalculate distance between two coordinates phpphp latitude and longitudeget radius from latitude and longitude phpcalculate distance between two gps coordinates formula phpphp distance between two coordinatessubtract two longitude in php give alphabetphp calulate distance between two locationphp longitget distance between two cordinates in phpformula to find distance between two coordinates phpphp get teh distance between 2 coordenates lat londistance calculation between two points phpcalculate distance between two coordinates in phpphp calculate distance between 2 pointscalculate distance from langitute and latitude phpget distance between two lat long phpget distance between two places in phpcalculate timing based on distance between latitude and longitude in phpphp a to b latlong dstancephp longitude 2b kmsubtract two longitude in phphow to calculate the distance between two points using phpfind all latitude and longitude to given latitude and longitude within one 1 km in phpcalculate distance between two points phpcalculatedistance phphow to calculate distance by longitude and latitude phpphp calculate distance in miles between two gps coordinatesgetdistance phphow to calculate distance between two places in phpdistance between two points in phpget distance between two points phpcalculate time from kilometer in phpphp difference betwwen coordenatescalculate distance between three coordinates in phpget distance between two coordinates in 3bphpphp coordinate distancecalculate no of time between two lat long in phpfectch near 10 km distance lat and long in phphow to get distance between two lat long in php 1 km 2 km etc calculate distance and timing between latitude and longitude in phphow to find out distance between two places phpcalculate km distance phphow to calculate distance between multiple latitude and longitude in phpcalculate distance between two cities using phpphp script calculate distance between cities freephp ditance between to cordinatephp use gps coordinates for distance betweenphp get distance between two lat longdistance between two locations in phpphp calculate trip distance given pointsphp distance between two coordinatescoordinates distance finder in phpcalculate distance of postal code longitude and latitude phpfind the exact distance between two locations in phpget distance between two time in phpfind distance between two points in phpcalculate distance betweemn 2 points phppedometer long lat php calculate timing and distance between latitude and longitude in phpget km distance lat and long phpphp get distance between two coordinatesdistance between two geoloction in phpget distance kilometers in phpcalculate distance and time between two locations in phpphp lat long distance calculatorhow to reduce lat long length in phpfind all latitude and longitude to given point and distanec and timing in phpcalculate distance from latitude and longitude phpcalculate distance between more than two coordinates in phpphp calculate distance between two addresseshow to calculate the distance between two coordinates of two different places in phpdistance between two location lag and long phplaravel calculate distance between two coordinatescompare get distance with coordinates phpdifference between two latitude and longitude in km phpcalculates the distance between two points within 50 km in phpcalculate distance by latitude and longitude phpphp calculate distance between multiple coordinatesphp calculate distance between coordinateshow to calculate distance between two latitude and longitude in phpget distance between two locations in phpdistance between points by geolocation phpphp calculate distance between two coordinatesget distance lat and long phpget distance from points phpphp distance between two lat longpoint to address phpphp calculate distance between more than two coordinatescalculate distance between two points in phpfind km between two places phpdistance between two points by road in phphow to check the distance between two sql dates in phpcalculate arrival time between two latlong in phpcalculate distance between two latitude longitude points in phpphp get distance between numbersget distance between two coordinates phpphp coordonate distancecalculate distance between two coordinates in km phpphp check lat lon distancecalculate radius latitude longitude phpdistance between two locations in php