0

I have an app where the user marks locations such as home, office etc. The latitude and longitude data for these locations are stored in sqlite DB. I am periodically checking the users current location. I want to check if the users current location falls in to a radius of a marked location.

Example, users coordinates for home are (a,b) how to find if the current coordinates (m,n) falls under a radius of 0.5 Km of home.

user340
  • 375
  • 12
  • 28

3 Answers3

3

You can just measure distance between two locations using Location.distanceTo() or Location.distanceBetween() methods. If the calculated distance is less than 500m, than it falls under the required radius. Hope this helps.

Egor
  • 39,695
  • 10
  • 113
  • 130
1

For distance measuring between two coordinates you can find a solution here:

Calculating distance between two geographic locations

Also you can make a database query to sort your records by distance: http://forums.phpfreaks.com/index.php?topic=175951.0

Community
  • 1
  • 1
Amir
  • 203
  • 1
  • 8
0

or, the old fashioned way: radius = sqrt( (m-a)^2 + (n-b)^2 ) assuming flat earth model. Once your distance is very great, this formula no longer applies

Martin
  • 4,711
  • 4
  • 29
  • 37