title: Query for nearby locations
body: <p>I am using Firebase to store users with their last scanned latitude and longitude. </p>
  
  <p>An entry looks like this:</p>
  
  <pre><code>"Bdhwu37Jdmd28DmenHahd221" : {
    "country_code" : "at",
    "firstname" : "John",
    "gender" : "m",
    "lat" : 11.2549387,
    "lon" : 17.3419559
  }
  </code></pre>
  
  <p>Whenever a user presses a specific "search" button, I want my Firebase function to fetch the people nearest to the person who sent the request.</p>
  
  <p>Since Firebase only allows for querying after one field, I decided to add the country_code, to kind of have some range-restrictions and query for that field. But it is still super slow when I load every user of a specific country and then check for the smallest distance between a given user and all the other users in the same country.</p>
  
  <p>Already with 5 users, the function takes like 40 seconds to achieve the results.</p>
  
  <p>I have also read about compound Indexes, but I would need to somehow combine the latitude and the longitude and query for both fields.</p>
  
  <p>Is there any way to either get a second and third query involved here (e.g. search for the same country_code, and then for a similar longitude and latitude) or do I have to solve this inside my server code ?</p>