Question

I have created a SqliteDatabase in Android which has two columns(along with other columns) with latitude and longitude information. I have to retieve the rows that are within the 500 meters circle around me, now I have my current Latitude and Longitude information, how to I compare and retrieve them?

thanks

Was it helpful?

Solution

how to I compare and retrieve them?

There are i guess more possible approaches. You could do it with well-designed WHERE clause but performance won't be good i think.

So i recommend you to fetch all rows into Cursor. Then loop through Cursor and compare each row's latitude and longitude with your currect location. Row that is in desired distance save into some helper structure for example into dynamic array (List for instance).

For calculate distance between two points you can use Euclidean distance. For converting degrees to decimal have look at this article.

Hope it helps you and made thing clearer.

OTHER TIPS

You'll probably have to use the Haversine Formula to work out the distance from yourself to each of the points

See here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top