php


How to find distance between two set of co-ordinates in php [closed]


Let suppose i have two set of co-ordinates, i got these co-ordinates from map source through android application and sent it to server, now server side will calculate distance between them and print.
Try This
<?php
$points = array
(
"point1" => "0,55" ,
"point2" => "0,52"
);
function get_distance($inputs)
{
$count = 1;
foreach($inputs as $x => $y)
{
echo $x." = (".$y.")<br>";
$p[$count] = explode(",",$y);
$count++;
}
$x1 = $p[1][0];
$y1 = $p[1][1];
$x2 = $p[2][0];
$y2 = $p[2][1];
$distance = sqrt(pow(($x2 - $x1) , 2) + pow(($y2 - $y1) , 2));
echo $distance;
}
get_distance($points);
?>
Try this:
function calculateDistance($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;
}
}
and you can call it like:
calculateDistance($latitude1, $longitude1, $latitude2, $longitude2, "K");
Reference

Related Links

JSON string (encoded from large array) got truncated when output to HTTP client
Regular expression to find word with in word in php
In prestashop How to pass a value from a php file into a template file
show category banner image on product pages woocommerce
How to host a PHP application in Openshift?
PHP variable is not an mysqli object
Zf2 pagination in categories (problems with routes)
Array unset not working in all circumstances
Corrupt ZIP files using PHP & PCLZip
Continually try to insert random unique values into table
CakePHP 2.5 Autocomplete
CodeIgniter DataMapper ORM memory issue
mysql combining data from multiple records in single record
Store iOS device token to a MySQL database
Mysql: fetch value from database and php array in single query
Php mail doesn't display images

Categories

HOME
xcode
compilation
kivy
typeerror
android-emulator
semantic-web
lvm
azure-data-lake
facebook-android-sdk
clone
telegraf
specifications
powermock
pushdown-automaton
twisted
mixpanel
nullreferenceexception
multiple-tables
tableview
hdl
raima
unordered-multimap
password-generator
python-appium
oracleforms
microprocessors
mapnik
osx-lion
microsoft-certifications
devtools
db2-luw
spinner
selenide
praat
newtons-method
distributed-caching
raytracing
robust
git-tfs
type-inference
nomad
code-push
audio-converter
karabiner
winston
sesame
dex
rcharts
msxml
dymola
bpms
allegro
clp
oci
node.js-connect
deferred-rendering
powerpoint-2013
onepage-checkout
apache-commons-digester
astropy
gluon-desktop
compositetype
flow-js
r.java-file
fiware-bosun
smacss
xcode6.3.1
distributed-r
stripe.net
autonumber
acceptance-testing
mongo-jackson-mapper
semicolon
chefspec
significant-digits
ckeditor.net
user-forums
kolite
sigar
will-paginate
botnet
grails-validation
mongrel
explicit
tabbarcontroller
zend-test
rawcontacts
ppc
spring-modules
projectpier
wmd-editor
jquery-effects
downcasting
rendering-engine
rootkit

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App