Portfolio for Aaron Dale

Projects - Feedback - Code

MySQL Distance Calculation

This function quickly estimates the distance between two points using GPS coordidates.

Without this function, an API call would need to be made to a GIS map service such as Google Maps which would significantly increase processing time.

Note that this function accounts for the curvature of the Earth but it doesn't account for distance traveled down roads so the values are estimates which turn out to be pretty close to a Google Map evaluation.
function getDistanceCalculated($subscriberID, $type, $id, $lat, $lng){ if($lat == 0 OR $lng == 0){ $lat = getSubscriberDetail($subscriberID, "current_latitude"); $lng = getSubscriberDetail($subscriberID, "current_longitude"); } $distance = SQL_Single("SELECT (((acos(sin((".$lat."*pi()/180)) * sin((`SHOP_LATITUDE`*pi()/180))+cos((".$lat."*pi()/180)) * cos((`SHOP_LATITUDE`*pi()/180)) * cos(((".$lng."- `SHOP_LONGITUDE`)*pi()/180))))*180/pi())*60*1.4515) as distance FROM shops WHERE SHOP_ID = $id"); $distance = ceil($distance); return $distance; }

Portfolio - Feedback - Code