Android Question "Near Me" ; how to approach this?

Cableguy

Expert
Licensed User
Longtime User
In an app I'm planning I will need a "near me" or "around me" button that will filter results by a max distance...
My question is, how to tackle this?
What is the best approach?
Circle all records and add those within the filter parameter to a new list? Is there a "service" available that does this checking?
 

eurojam

Well-Known Member
Licensed User
Longtime User
I would suggest to use a spatialite DB, which is a sqlite with spatial capabilities. there is a lib from Martin: https://www.b4x.com/android/help/spatialite.html.
then you can use spatial queries to select the data from the database like:
B4X:
SELECT *
FROM table AS a
WHERE ST_DWithin (mylocation, a.LatLong, 10000) -- 10km
ORDER BY ST_Distance (mylocation, a.LatLong)
LIMIT 20
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Nice, thanks!
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
If you are looking for a simple way, i realised in an 'quick and dirty' manner: I calculated the the difference between the x - values and the difference of the x values, and added them together; you could use a factor for the x or y value, so that distance on x values is the same as the y values. So the smallest value is the nearest and so on.
I have this idea inside a sql query and it is working...
 
Last edited:
Upvote 0
Top