Note that there are some explanatory texts on larger screens.

plurals
  1. POQueries to find places within a given lat/lng
    primarykey
    data
    text
    <p>So I'm trying to display lists of places within a range of the given lat/lng. I have no problem with this:</p> <p>Places within one mile (list of places...)</p> <p>Using something like</p> <pre><code>SELECT * FROM places WHERE lat &lt; $latmax AND lat &gt; $latmin AND lng &lt; $lngmax AND lng &gt; $lngmin </code></pre> <p>But then I want to list places within two miles, BUT not within one mile -- that is, I don't want to repeat the results from the first query.</p> <p>Here's one version of what I've tried:</p> <pre><code>$milesperdegree = 0.868976242 / 60.0 * 1.2; // 1 mile -- this works $degrees = $milesperdegree * 1; $latmin = $lat - $degrees; $latmax = $lat + $degrees; $lngmin = $lng - $degrees; $lngmax = $lng + $degrees; $query = "SELECT * FROM places WHERE lat &lt; $latmax AND lat &gt; $latmin AND lng &lt; $lngmax AND lng &gt; $lngmin"; // 2 miles -- this doesn't work $degrees_2 = $milesperdegree * 2; $latmin_2 = $lat - $degrees_2; $latmax_2 = $lat + $degrees_2; $lngmin_2 = $lat - $degrees_2; $lngmax_2 = $lat + $degrees_2; $query = "SELECT * FROM places WHERE "; $query .= "lat BETWEEN $latmax AND $latmax_2 AND lng BETWEEN $lngmax AND $lngmax_2 OR "; $query .= "lat BETWEEN $latmin AND $latmin_2 AND lng BETWEEN $lngmin AND $lngmin_2 OR "; $query .= "lat BETWEEN $latmax AND $latmax_2 AND lng BETWEEN $lngmin AND $lngmin_2 OR "; $query .= "lat BETWEEN $latmin AND $latmin_2 AND lng BETWEEN $lngmax AND $lngmax_2"; </code></pre> <p>That's not doing it. I'm guessing it's just some logic I can't wrap my head around on Sunday afternoon, but I'm probably doing something else wrong too. Any input is greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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