php


how to get distance between points using latitude and longitude using php?


I am trying to get distance between two location.
Here one location is user input and another location is my store location.
I want to show the the distance between there input location to my store location.
To get user location we use form, where user share there zip code and we convert that zip to longitude and latitude. And in my data base i stored the store location and its respective longitude and latitude.
Here in this case can any one help me to get distance.
Thanks
GeoDataSource team develop a very useful function to achieve this:
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>";
Reference

Related Links

submit a form, but could not get input values
I'm not understanding something at PHP handling
PHP autoloader class to load files from two or three different path
Load complete MySQL table into an HTML page [closed]
Extracting triples from text in php using Stanford-NLP?
images upload when “insert” is used, but doesnt when “update” is used
I want to compare two comma delimited strings in PHP and keep only the values that appear in both
Wordpress Permalinks does not work
Sending email through PHP?
Laravel HTML and SQL sanitisation
PHP loop Foreach + While
PHP - upload files [POST]
“Incomplete Headers” with PHP's mail() function
Best way to define path in PHP
Error while json creation in php
Commands out of sync; you can't run this command now: multiple queries, not simultaneous

Categories

HOME
spring-data
clearcase
d3.js
applescript
haproxy
braintree
risk-management
web2py
swift2
iptables
video-streaming
wagtail
kurento
driver
heuristics
xamarin-zebble
parsley.js
sap-fiori
business-intelligence
createjs
xbap
jquery-file-upload
squid
corona
sonicwall
google-sites
pickle
nullreferenceexception
amazon-mws
connection-refused
tortoisemerge
acrobat
javax.persistence
fatfs
windowsiot
vcenter
riotjs
fotorama
xcrun
polyml
db2-luw
keyboard-layout
netstat
love2d
ms-dos
unification
grunt-contrib-watch
uipickerview
opal-framework
dagger
fluid-mac-app-engine
spooler
morphline
realstudio
windows-media-player
scala-breeze
knockout-2.0
md5-file
head.js
visual-format-language
http-basic-authentication
dtd
mechanicalturk
word-2016
ltrace
wildfly-9
bpms
pbx
petsc
portal
metabase
e
carmen
android-4.2-jelly-bean
groovyfx
static-methods
sharepoint-apps
polymerfire
gwt-syncproxy
seadragon
myfaces
python-cffi
sablecc
jcheckbox
datagridcomboboxcolumn
window-resize
storing-data
ecos
windows-messages
csslint
air-native-extension
jack
pre
property-injection
sensormanager
pbkdf2
google-code-prettify
web-frameworks
ui-design
reentrancy
cyrillic
towers-of-hanoi
taskkill
jdom
boost-foreach
server-variables
firefly-mv
botnet
css-friendly
dip
eaccelerator
pinax
eai
sqlsitemapprovider
stretchblt

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile