Created
June 4, 2011 18:59
-
-
Save mheadd/1008202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getSql($max,$type,$lat,$lon) { | |
| GLOBAL $round, $limit, $crime_types; | |
| $sql = "SELECT BLOCKSITEADDRESS, OFFENSE, REPORTDATETIME, ROUND(((ACOS( SIN($lat * PI()/180 ) * SIN(LATITUDE * PI()/180 ) + COS($lat * PI()/180 ) * COS(LATITUDE * PI()/180 ) * COS(($lon - LONGITUDE) * PI()/180))*180/PI())*60*1.1515),$round) AS DISTANCE FROM crime_incidents_2008 "; | |
| if($type > 0) { | |
| $sql .= 'WHERE OFFENSE = \''.$crime_types[$type].'\' '; | |
| } | |
| $sql .= "HAVING distance <= $max ORDER BY DISTANCE ASC LIMIT 0 , $limit"; | |
| return $sql; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Calculate the distance between 2 points. | |
| function calculateDistance($lat1, $lon1, $lat2, $lon2) { | |
| return 3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment