Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP to Javascript Arrays and GPS locations
- var people = [ ['Type1', -33.890542, 151.274856],
- ['Type2', -33.923036, 151.259052],
- ['Type2', -34.028249, 151.157507],
- ['Type2', -33.80010128657071, 151.28747820854187],
- ['Type1', -33.950198, 151.259302]
- ];
- // MySQL query in PHP
- // btw, I'm storing GPS coordinates in decimal format like 51.123234
- $varA = "(POW(SIN((gps_lat - $latitude) / 2 * 0.017453293), 2) + COS($latitude * 0.017453293)
- * COS(gps_lat * 0.017453293) * POW(SIN((gps_lon - $longtitude) / 2 * 0.017453293), 2))";
- $query = "SELECT *, (6378.140 * 2 * ATAN2(SQRT($varA), SQRT(1-$varA))) AS distanceInKm ";
- $query += 'FROM Office ORDER BY distanceInKm');
- $mysqli->query($query);
- // ...
- // the magic constant 0.017453293 is PI / 180 (just check the link below).
- dlon = lon2 - lon1
- dlat = lat2 - lat1
- a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
- c = 2 * atan2(sqrt(a), sqrt(1-a))
- d = R * c
Add Comment
Please, Sign In to add comment