mercredi 7 octobre 2015

Find elements within 5km of a given longitude/latitude

I am creating an app that has a features that needs to find supermarkets that are in a 5km range from the user.

I thought that using longitude and latitude would be a good idea (I should store those two values as atributes on a supermarket table and I'd be ready to go).

Once I created my table and inserted it's values, I went to look for a solution on how could I get those supermarkets from my database. What I had in mind would be a select with a not so complex WHERE clause that would solve all my problems. Instead, I found a bunch of different ways of doing it:

1) Create an square around the user location, find the supermarkets that are inside of it and then find the ones that are actually in that range

2) Create extra coluns on your table

3) Use the cosine law

4) Find out how to convert latitude/longitude to kilometers and use Pythagorean Theorem (for ranges that are not so wide)

The three problems are that any solution is made on the database (with a where clause), I have no idea which one has more performance or is better in any aspect and it's not like I'm getting how to use those exemples. So... What should I use remembering that I have and SQLite database and android?

Thanks :)

Aucun commentaire:

Enregistrer un commentaire