-1

I would like to calculate distance between 2 points of latitude and longitude in PHP (NOT IN ANDROID)**i have read about **Haversine Formula and Spherical Law of Cosines for calculate distance between two points but my main motive is get best location difference between 2 points in Meters.

For Example Two devices place at next to each other and that android devices is sending location to server,So we need to take that location of each device and calculate minimum distance between these 2 device in meter.Result from Server after calculation should be like in 2-3 meters when device is placed next to each others

So what are the possible ways to calculate minimum distance between two device in meters when device next to each other on server side

Note : I need to calculate distance which i got in kms or miles which is big difference when device is next to each other. Haversine Formula and Spherical Law of Cosines is i found best way to calculate but i need to do more in these formulas to get minimum difference between 2 device.Not on Android Device. This question is not related to This Question

Community
  • 1
  • 1
androidXP
  • 1,692
  • 3
  • 27
  • 58
  • @KNeerajLal This question is for PHP server side not for app android side.Read Question Before mark as duplicate – androidXP Sep 19 '16 at 09:12
  • Are you looking for line of sight or based on roads? Have you looked at the distance matrix part of the API? – Takarii Sep 19 '16 at 09:57
  • @Takarii not based on roads i am looking for solution to get minimum distance between 2 device by using above formula and it should be under 5 meters when 2 device is place to each others – androidXP Sep 19 '16 at 10:01

1 Answers1

0

I have used the Haversine formula in PHP to calculate distance in kms between two geocoordinates:

// Haversine formula
function geoDistance($lon1, $lat1, $lon2, $lat2) {
    $R = 6371; // Radius of the earth in km
    $dLat = deg2rad($lat2 - $lat1);
    $dLon = deg2rad($lon2 - $lon1);
    $a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon/2) * sin($dLon/2);
    $c = 2 * atan2(sqrt($a), sqrt(1-$a));
    $d = $R * $c; // Distance in km

    return $d;
}

I guess, having enough precision in lon and lat would yield a result that multiplied by 1,000 migth be useful as a measure of distance in meters, right?

According to https://gis.stackexchange.com/questions/8650/measuring-accuracy-of-latitude-and-longitude the fifth decimal place is worth up to 1.1 m: it distinguish trees from each other.

Community
  • 1
  • 1
  • 1
    This might work but i used similar like this which doesn't return distance in under 5-10 meters when 2 device next to each other.Still i will give try to this one – androidXP Sep 19 '16 at 09:24
  • 1
    You will need 5 decimals precision in both lon and lat – Juan Ignacio Pérez Sacristán Sep 19 '16 at 09:28
  • That's how android device generate location Take a Look 28.5312119 and 77.2569046 its more than 5 and i think if i remove few from last then location will be not accurate as it should be.Please take a look at this – androidXP Sep 19 '16 at 09:39
  • 1
    According to http://gis.stackexchange.com/questions/8650/measuring-accuracy-of-latitude-and-longitude the fifth decimal place is worth up to 1.1 m: it distinguish trees from each other. – Juan Ignacio Pérez Sacristán Sep 19 '16 at 09:43
  • 1
    Thankyou for the above link its really very informative and i need to cut down difference as much as i can so for this i think i need to use more then 5 decimal places ? – androidXP Sep 19 '16 at 09:52