Hi Everyone,
I'm trying to use a math equation ( see bottom of post) to get the distance of two points. I am able to get the data from the user and the server. However, when I try to use the equation, NAN(not a number) is displayed. I tried to resolve this issue by casting the variables to (float) but this did not work either. I'm not sure what is off here. Can you take a look?
// get user input
$userLong=(float)$_POST['userLong']=-73.9599609375;
$userLat=(float)$_POST['userLat']=40.8169272319157;
[/code]
//data was supplied from the server in the while loop. Use foreach loop to parse data for getDistance function
foreach ($_SESSION['events'] as $event) {
echo $event["long".$i];
$eventLong=$event["long".$i];
$eventLat= $event["lat".$i];
$distance = getDistance($userLat,$eventLat, $userLong, $eventLong);
echo $distance;
}// end foreach
// for each loop supplied data use in equation below to get distance.
function getDistance($lat1,$lat2,$lon1,$lon2){
$lat1 = (int) $lat1;
$lat2 = (int) $lat2;
$lon1 = (int) $lon1;
$lon2 = (int) $lon2;
$radians =6371; //km
$d=acos(sin($lat1) * sin($lat2) + cos($lat1)* cos($lat2)* cos($lon1-$lon2)* $radians);
return $d;
}