The following code will give you the distance in miles from point A to point B lat and lon:
[php]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(42.0337712, -70.9623546, 42.351532, -71.060661, “M”) . " Miles
";
?>[/php]
I need something like this that will use data from a Mysql database:
[php]echo distance($HTML5JavascriptValueMyLat, $HTML5JavascriptValueMyLon, $row[‘MysqlLat’], $row[‘MysqlLon’], “M”) . " Miles
";
[/php]
I want the $MyLat and $MyLon to be my actual location. Mobile phones say “Allow www.xyz.com to access your location”, I need to get my location and somehow put it into those variables.
There is a code in HTML 5 that gets your location using javascript, how can I take that javascript value and add it to $mylat, $mylon?
My overall goal is to query a table that shows the distances in miles using Latitudes and Longitudes from a users location. “You are x Miles away from Business XYZ”
Thanks Everyone!!