0

i have a project to sort data by the nearest location. I want to show list of vehicle based on the nearest location of user. I store latitude and longitude in firebase. Is there a way to implement it in my project? I have no idea and i haven't found clue about this. this is my firebase : firebase

and this is my mockup to sorting the nearest vehicle : mockup nearest

Please help.. Thankyou.

Mpa
  • 5
  • 3
  • Please **visit** the **[help center](http://stackoverflow.com/tour)** and take the tour to see what and how to ask. – B001ᛦ Dec 15 '17 at 13:09
  • As B001 commented, please improve your question. and break your problem down in small problems, cause if you have a lat-lon database it's easy: look in the firebase [docs](https://firebase.google.com/docs/database/web/lists-of-data) how to sort & filter data. filter example: startAt(yourLat-10); endAt(yourLat+10); to retreive every db entry with a Lat that is "close" to you. – washichi Dec 15 '17 at 13:16
  • sorry.. now, i've edited my question. please check it.. – Mpa Dec 15 '17 at 23:32

1 Answers1

0

I would probably use Pythagorean theorem. Using Cartesian coordinates distance projected on the x axis is longitude1-longitude2 and distance projected on the y axis latitude1-latitude2. I call this a flat earth theory and it should be accurate enough but for more precision ‘haversine’ formula is more accurate but slower to calculate.

Pomagranite
  • 696
  • 5
  • 11
  • yes, thankyou for your answer.. but i have not clue how to implement it on my project.. @Pomagranite – Mpa Dec 15 '17 at 23:33
  • I don't see your code so I have no way to help. Can you post the portion of code this question is about? – Pomagranite Dec 16 '17 at 03:08