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:
2) Create extra coluns on your table
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 :)
ADDING MORE INFORMATION:
The first problem was to know which one I should use. The problem I had with this one was the this:
My user location is:
longitude = -22.82753105; latitude = -47.03398022;
My where statement
WHERE latitude < -47.078946300295925 AND
latitude > -46.989014139704054 AND
longitude > -22.76155626735494 AND
longitude < -22.89350583264506
I have a market on my database which location is the same the user and I do get a list with this very element once I select the ones that are in the square, but when I iterate on my list, it removes my element from the list bacause the if return FALSE.
if (getDistanceBetweenTwoPoints(mercado, userLocation) <= RANGE)
On the getDistanceBetweenTwoPoints, if I debug it, I get:
dLat = -0.4224822382331485
dLon = 0.4224822382331485
lat1 = -0.39841557692373836
lat2 = -0.8208978151568869
a = 0.07157979929009457
c = 0.5416864422451098
d = 3451084.323543594
And since the if compares "d" with range, it's like this:
if(3451084.323543594 <= 5000) { //my range is 5km
// keep element
else
// remove it from list
Does anyone can tell me what is the problem??