Am developing MAP app. It saves several thousands for latitude & longitude details to draw overlay.
When user touches the overlay it wants to fetch the nearest latitude and longitude from the saved record in SQL.
I use:
SELECT *
FROM track_points
WHERE segmentId = '22'
ORDER BY (ABS(latitude - 25.312005) + ABS(longitude - 91.730433))
It exactly does the same but the problem is when the particular overlay has several thousands of lat and longi details. It takes a long time to complete the above query.
It runs thought the entire DB data to get one point, even when the nearest data is fetched.
Just when 28.2525 is given I need something near 25.2520 or what ever it is and stop with that. I don’t want to start from 22.23252 or something in row 10 and reach 25.2520 at row 5000 and yet conti till the last row.
First, continue to investigate if Spatialite is what you need.
However, you need to cut down the number of points that the query is considering:
You want to set the boundaries as narrow as possible but wide enough to be sure you get at least one result. If your lattitude and longitude are a regular lattice then this is trivial.
You can use
BETWEEN @value - @tolerance AND @value + @toleranceto detrimine the values on the fly.