$sql = "SELECT *, ( 6371 * acos( cos( radians(37) ) * cos( radians( ".$_GET["lat"]." ) ) * cos( radians( ".$_GET["lng"]." ) - radians(-122) ) + sin( radians(37) ) * sin( radians( ".$_GET["lat"]." ) ) ) ) AS distance FROM markers HAVING distance < 0.5 ORDER BY distance LIMIT 0 , 1";
Based on my quick run through with death lol I realized my $_GET doesnt make sense as to what it's doing. The original formula is such
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;
I can't find any good tutorials on how to implement this. I just need to know where to put it! My latitude and longitude.. in the sql statement so it can calculate IF around each other to group together.
This is the google tutorial I got the code from.
And a members answer to the problem.. I feel there was hardly explanation on how to use this formula in sql..
UPDATE
I don't mean to bash. I know they explained it rather obvious, I just lack the ability to understand it for some reason. Much apologies links.
UPDATE
Still having troubles. I tried adjusting the code as such. Is this being done right? Cause I insert two geolocation coords that are the same and they should group together, but are not.
<?php
$lat1=$_GET["lat"];
$lng1=$_GET["lng"];
$lat2=$grouping[$counter][1];
$lng2=$grouping[$counter][2];
$sql = "SELECT id, status, ( 6371 * acos( cos( radians($lat1) ) * cos( radians( $lat2 ) )
* cos( radians( $lng2 ) - radians($lng1) ) + sin( radians($lat1) ) * sin(radians($lat2)) ) ) AS distance FROM markers HAVING distance < 0.5 ORDER BY distance LIMIT 0 , 2;";
?>