title: Flutter & firebase get docs by geohash
body: <p>I'm trying to get a documents based on a geohash upper and lower bounds. 'Location A' is the location of a user, and we're trying to find other locations that are within the bounds of 'Location A' in firebase. I was following this tutorial</p>
  <p><a href="https://levelup.gitconnected.com/nearby-location-queries-with-cloud-firestore-e7f4a2f18f9d" rel="nofollow noreferrer">https://levelup.gitconnected.com/nearby-location-queries-with-cloud-firestore-e7f4a2f18f9d</a></p>
  <p>and checking with this website</p>
  <p><a href="https://www.movable-type.co.uk/scripts/geohash.html" rel="nofollow noreferrer">https://www.movable-type.co.uk/scripts/geohash.html</a></p>
  <p>The coordinates of 'location A' are <code>52.462570419161594, -2.0120335164758725</code> and the coordinates of 'Location B' are <code>52.46648448588268, -1.9841125656313279</code>. These are very close to eachother so, with the code below i'd assume that with the firebase query it'd return 'Location B' when querying from 'Location A's geohash but this isn't happening and it's because the <code>getGeohashRange</code> function is returning the wrong value but i'm not sure what i'm doing wrong</p>
  <p>Location A geohash = 'gcqd6'
  Location B geohash = 'gcqd6'</p>
  <p>The upper &amp; lower that the <code>getGeohashRange</code> is returning =
  lower: &quot;mpt5mf52n18z&quot;
  upper: &quot;mptmvc2wncyc&quot;</p>
  <p>This is the code &amp; firebase query</p>
  <pre><code>// Get the geohash upper &amp; lower bounds
  GeoHashRange getGeohashRange({
    required double latitude,
    required double longitude,
    double distance = 12, // miles
  }) {
    double lat = 0.0144927536231884; // degrees latitude per mile
    double lon = 0.0181818181818182; // degrees longitude per mile
  
    double lowerLat = latitude - lat * distance;
    double lowerLon = longitude - lon * distance;
  
    double upperLat = latitude + lat * distance;
    double upperLon = longitude + lon * distance;
  
    GeoHasher geo = GeoHasher();
  
    var lower = geo.encode(lowerLat, lowerLon);
    var upper = geo.encode(upperLat, upperLon);
  
    return GeoHashRange(lower: lower, upper: upper);
  }
  
  class GeoHashRange {
    late String upper;
    late String lower;
  
    GeoHashRange({
      required this.upper,
      required this.lower,
    })
  }
  
  
  
  // Query firebase for locations
  Stream&lt;List&lt;Garage&gt;&gt; getLocalGarages(Position position) {
    GeoHashRange range = getGeohashRange(
      latitude: position.latitude,
      longitude: position.longitude,
    );
  
    var ref = _db
        .collection('garages')
        .where(&quot;geohash&quot;, isGreaterThan: range.upper)
        .where(&quot;geohash&quot;, isLessThan: range.lower);
  
    return ref.snapshots().map(
          (list) =&gt;
              list.docs.map((doc) =&gt; Garage.fromJson(doc.data())).toList(),
        );
  }
  </code></pre>