Member-only story
Add Geo-search to your website/app in just 9 lines of code
Ever wanted to add advanced features like geo-search to your website or app, but the process felt too overwhelming?
Well, I will let you in on a trade secret! 🤫
It can be done with JUST 9 LINES OF CODE using Firestore! 🤯
Let’s get started!
Add Geo-hash to your data
Before you can use geo-search, you would need to add one additional field to your data called geohash
.
To generate the geohash
, you can use a library called geofire-common.
npm install geofire-common
The geohashForLocation
function accepts the latitude and longitude as input and returns a geohash
for the location.
await setDoc(doc(db, "cities", "LA"), {
name: "Los Angeles",
lat: 34.0,
long: -118.2,
// store geohash
geohash: geofire.geohashForLocation([lat, lng]),
});