Hello everyone šŸ‘‹ Is there a way to calculate di...
# flutter
a
Hello everyone šŸ‘‹ Is there a way to calculate distance between coordinates just like firebase Geofire in supabase?
k
You will need to create an RPC function for this. and fyi: you can't really say like firebase, because geolocation in firebase is just trash and costy.
anyway, lets say u have a geo location stored in ur database u can then easily do this
Copy code
ST_Distance(myTable.savedLocation, ST_GeogFromText(my_location))
this will return u a distance between two locations, u can also use it to order by ur query šŸ™‚
a simple function can be
Copy code
$$;
CREATE
OR REPLACE FUNCTION public.select_nearby_feed(my_location text) RETURNS SETOF feed LANGUAGE sql AS $$ 
   select * from feed 
    ORDER BY ST_Distance(feed.location, ST_GeogFromText(my_location)), created_at DESC;
$$;
and from flutter.
Copy code
_supabase.client.rpc('select_nearby_feed', params: {'my_location', 'POINT(longitude latitude)'})
.execute();
look into postgis
b
or you can wait til supabase functions are out
b
Did you get this resolved? Iā€™m doing this using a PostgreSQL function and can share it with you if you need it.