leonardo watch
leonardo watch

Reputation: 53

What if i want show all location from my database within radius 1000 meters from my current location?

I want show all locations from my database. I have Current location and I want to display all locations from the database that are within a radius of 1000 meters of my current location. Database table has the following fields.

DB: Name, latitude, longitude.

Thanks.

Upvotes: 2

Views: 499

Answers (1)

Nishita
Nishita

Reputation: 924

You can have a listener on your location. Every time your location changes by a set amount, say 50m, you can make a database call and retrieve the set of locations. Calculate the distance between your current location and the stored locations using Google's Distance Matrix Api and sort them accordingly. Retrieve the locations that fall within your desired radius and display them.

If you can use Firebase database, then you can all this automated for you by using geofire. Geofire provides realtime location querying. Which is exactly what you are trying to achieve. You store key value pair of your locations in the database. Query the database using your current location and radius and GeoFire will do the rest for you. https://github.com/firebase/geofire

Upvotes: 3

Related Questions