Search code examples
postgresqlflutterpostgisgeohashing

why is geohash different from postgis?


I'm a bit confused with Geohash Geoflutterfire vs Geohash postgis, and I would like to have some explanations, please.

I have a Flutter Dart application that relies on Firebase. I am using the GeoFlutterFire plugin that Geohashes the addresses for me.

So the coordinates (47.3055771,3.4905722) have Geohash u06mp7tyb after they have been processed by geoflutterfire.

I have to mass process files that I have geocoded to assign a geohash to each address line. To make my life easier, I have decided to use postgresql/postgis. And so, for the address (47.3055771,3.4905722) indicated, I do :

SELECT ST_GeoHash(ST_SetSRID(ST_MakePoint(47.3055771,3.4905722),4326),9);

This gives me t09eu7qy5, i.e. a result that is totally unusable in view of the data already entered in firebase.

Where does this discrepancy between the u06mp7tyb geohash and the t09eu7qy5 geohash come from? And how to solve it


Solution

  • For postgis, you have to swap latitude and longitude like this :

    SELECT ST_GeoHash(ST_SetSRID(ST_MakePoint(longitude, latitude),4326),9);
    

    I've been stuck on this for two days.... 😭😵‍💫