Guest User

Untitled

a guest
Aug 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. PHP to Javascript Arrays and GPS locations
  2. var people = [ ['Type1', -33.890542, 151.274856],
  3. ['Type2', -33.923036, 151.259052],
  4. ['Type2', -34.028249, 151.157507],
  5. ['Type2', -33.80010128657071, 151.28747820854187],
  6. ['Type1', -33.950198, 151.259302]
  7. ];
  8.  
  9. // MySQL query in PHP
  10. // btw, I'm storing GPS coordinates in decimal format like 51.123234
  11. $varA = "(POW(SIN((gps_lat - $latitude) / 2 * 0.017453293), 2) + COS($latitude * 0.017453293)
  12. * COS(gps_lat * 0.017453293) * POW(SIN((gps_lon - $longtitude) / 2 * 0.017453293), 2))";
  13.  
  14. $query = "SELECT *, (6378.140 * 2 * ATAN2(SQRT($varA), SQRT(1-$varA))) AS distanceInKm ";
  15. $query += 'FROM Office ORDER BY distanceInKm');
  16.  
  17. $mysqli->query($query);
  18. // ...
  19.  
  20. // the magic constant 0.017453293 is PI / 180 (just check the link below).
  21.  
  22. dlon = lon2 - lon1
  23. dlat = lat2 - lat1
  24. a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
  25. c = 2 * atan2(sqrt(a), sqrt(1-a))
  26. d = R * c
Add Comment
Please, Sign In to add comment