-2

In PHP, how to subtract $Longitude_1 = 72.8790721063599 from $Longitude_2 = 82.22? These are decimal degree values from Google geocoding.

I need to find the difference and convert it into time.

The time value comes close to 40 minutes as I know in this case.

Also, 1 Degree = 4 mins and not 60 mins when it comes to time differences from longitudinal positions. So if I have the coordinate difference in degrees, I can convert the same to time units. It is to get to the Local Mean Time at the concerned longitude!

Viktor Tango
  • 453
  • 9
  • 19
  • They're not radians, they are degrees. You're not converting it into time, you're converting decimal degrees to degrees, minutes, and seconds (often abbreviated as DMS). – Brad Jul 21 '14 at 20:24
  • Okay I agree, its Decimal Degrees (DD) not radian. And what I mean to use is 1 dg = 4 mins in the end. But I do not know how to get the difference in PHP with two DD values at hand. – Viktor Tango Jul 21 '14 at 20:46
  • 1 degree is 60 minutes. – Brad Jul 21 '14 at 20:47
  • Come on, when it's about longitude and latitude and time, its 1 deg = 4 mins. Please see here: http://www.sunlit-design.com/infosearch/equivalence.php . What you mean is in the hour and the minute hand like given here: http://mathforum.org/library/drmath/view/65468.html – Viktor Tango Jul 21 '14 at 20:50
  • Well, how do you get the difference of values which are in DD format? and then convert the values to Degrees so that time can be obtained in the end. It's not trivial for me, can you help!!!!! – Viktor Tango Jul 21 '14 at 21:06

1 Answers1

0

Addressing what I see to be your core questions here:

Well, how do you get the difference of values which are in DD format?

$Longitude_2 = 82.22;
$Longitude_1 = 72.8790721063599;

//get the difference
$diff = $Longitude_2 - $Longitude_1; //9.3409278936401

and then convert the values to Degrees so that time can be obtained in the end.

Your answer, stored in $diff, is already in decimal degrees, so there's nothing to convert. Per your source, 1 degree = 4 minutes time, so simply multiply:

//get the time value
$diff_time = $diff * 4; //37.3637115745604

So, the actual time value is close to 37 minutes for your particular case.

Brian Driscoll
  • 19,373
  • 3
  • 46
  • 65
  • I had in the mean time used something like this $lngDeg = (82.22 - $lngtxt) * (M_PI/180); $wholeD = floor($lngDeg); $fractionD = $lngDeg - $wholeD; $lngM = $fractionD *60; $wholeM = floor($lngM); $fractionM = $lngM - $wholeM; $lngS = $fractionM *60; Using the above I got 37.84 Minutes Yours is much better perhaps. No PI value is involved!!! Thank you. – Viktor Tango Jul 21 '14 at 21:36