Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to define a radial search area around a lat/lng position?
    text
    copied!<p>I am working on a project, where each user has its own coordinates lat / lng, extracted from google geocoder service...</p> <p>now I want to implement a search function -> you can enter the radius (km) and if someone is within the radius, the profile will pop up...</p> <p>it wasnt to difficult to get this to work, when the search area is actually a square, but how do I get this to work, with a circle as search area?</p> <p>here is the code, to build the "search" part of the mysql query:</p> <pre><code>// This is the location of the user who submitted the search function. mysql_select_db("$db_profile"); $sql = "SELECT location_lat, location_lng FROM location WHERE id = '$global_id'"; $sql = mysql_query($sql); $row = mysql_fetch_array($sql); // The coordinates of the user. $lat = $row['location_lat']; $lng = $row['location_lng']; // the entered radius in kilometers - here it is converted to degree (1° = 111km). $x_degree = $global_search_radius_value / 111; // define the search grid (it is a squere! but I want a circle!). $lat_neg = $lat - $x_degree; $lat_pos = $lat + $x_degree; $lng_neg = $lng - $x_degree; $lng_pos = $lng + $x_degree; // build the search part of the mysql query $heredoc_search_radius = &lt;&lt;&lt;EOD AND ($db_profile.location.location_lat &gt; '$lat_neg' AND $db_profile.location.location_lat &lt; '$lat_pos' AND $db_profile.location.location_lng &gt; '$lng_neg' AND $db_profile.location.location_lng &lt; '$lng_pos') EOD; </code></pre> <p>how can I use a circle instead of the squere!?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload