Units is in miles. It looks like you've got latitude and longitude reversed/swapped. Valid range for latitude is only -90 to +90, it can't be -107 (degrees). If you mean to specify a location in Colorado west of Denver, halfway to Grand Junction, swap the values for latitude and longitude....

This was a simple syntax issue...The values that corresponded with the query was not noted well. In the PHP file you can't write set and declare variables using the $. Original: set $orig_lat=32.42; set $orig_long=-23.550; set $bounding_distance=1; Solution: $orig_lat=32.42; $orig_long=-23.550; $bounding_distance=1; ...

It appears you got a little tripped up by the Haversine formula. You switched the $setlong and location_longitude terms in the third cosine term. I switched them around to get this: $setlat = 13.5234412; $setlong = 144.8320897; $awaka = "SELECT 'location_id', ( 3959 * acos( cos( radians(?) ) * cos(...

Just record the displacement every x seconds or so, and sum the displacements. You will have a fairly good approximation. Or just record the points at different times first, and then do the calculation at the end. var checkpoints = [], interval = null; function record() { checkpoints.push( /* current...

php,mysql,sql,sql-server,haversine

You need to have the condition in where clause not having SELECT *, count(*) FROM (SELECT *,ROUND(((ACOS(SIN(51.4811109 * PI() / 180) * SIN(latitude * PI() / 180) + COS(51.4811109 * PI() / 180) * COS(latitude * PI() / 180) * COS((-0.433641 - longitude) * PI() / 180)) * 180 /...

I believe your equation is wrong. Here is a javascript version you can compare against: http://www.movable-type.co.uk/scripts/latlong.html The difference is your terms Math.cos(lat1) * Math.cos(lat2). You need to convert lat1 and lat2 to radians first....

You cannot use calculated fields on a where or having clause. Create a view or use a subquery Try this: select * FROM (SELECT *, ( 3960 * acos( cos( radians( 33.650800 ) ) * cos( radians( Latitude ) ) * cos( radians( Longitude ) - radians( -117.891729 ) )...

Use the Haversine formula to find the users that are within a specified distance from a specified point: function getNearbyUsers(lat, lng, distanceInKm, users) { var R = 6373; var latRad = lat * Math.PI/180; var lngRad = lng * Math.PI/180; var returnUsers = []; for (var i = 0; i...