Search nearby latlng using firebase

-uniqueid1 latitude: 30.7188235 longitude: 76.810132 -uniqueid2 latitude: 30.7188235 longitude: 76.810132 

there are 1000 such entries in firebase, I want to find unique methods that are closest to a specific long / lat. I started using startAt () and endAt (), but did not succeed. How do we implement a conditional sentence and a few queries. I am looking for a request

 SELECT uniqueids from table where (lon-specific_lon)^2+(lat-specific_lat)^2<CONSTANT. 
+5
source share
2 answers

What you are looking for is part of the Firebase Geofire library. It uses Geohash to work smartly with a Firebase restriction, which you can only query on a single value.

Geohash is a way to pass longitude and latitude into one value, suitable for range queries.

See the Github repository for Geofire for more information.

+12
source

I don’t believe there is a built-in way to do this, but one way could be to create a square grid and assign each location to an area - for example, an area

{x: 2, y: 4}

enter image description here

Then you can return all the locations in the region and neighboring regions, returning everything in a certain range that could be configured in the data call. For example, if you want to return everything within 1 area of {x: 2, y: 4} , you should return:

 {x: 1, y: 3} {x: 1, y: 4} {x: 1, y: 5} {x: 2, y: 3} {x: 2, y: 4} // The region you're in right now {x: 2, y: 5} {x: 3, y: 3} {x: 3, y: 4} {x: 3, y: 5} 

enter image description here

This will return the square surrounding your region and all the places on that square. If you need it to be round, you could crop your choice on the front side. This is not an ideal solution, but it may be a way to do what I think you are trying to accomplish, which is less data.

+5
source

Source: https://habr.com/ru/post/1243698/


All Articles