0

I'm having a database with over 6000 GPS locations. I'd like to compare the user's current location and detect whether the user is within distance of 10 meters from any of the 6000 locations.

How can I achieve that without going thorugh all 6000 points and calculating their relative distance ?

Thanks, Daniel

UPDATE: How about if I'll put the user's current location in the middle of a 5^2 meter rectangle and extract all the locations with current.latitude between bottm_right.latitude and top_left.latitude and same goes for longtitude ?

David V
  • 11,531
  • 5
  • 42
  • 66
Daniel Haviv
  • 1,036
  • 8
  • 16

3 Answers3

0

A simple way is to create another database or modify your current database to index from a geohash. This approach will not handle location density very well though, so if your points are not well distributed it may not be much of an improvement.

David V
  • 11,531
  • 5
  • 42
  • 66
0

Logically, unless the 6000 locations are logically grouped somehow you are going to have to go through all 6000.

if you have control over the database structure you could organize the GPS locations into regions (groups of locations that are close to each other) then this should bring your 6000 down to (depending on how fine grain you want to go) to 10,20,30, or 100 groups each of these groups could have a mid point location and total distance of the group then you could loop through the group with that total distance in mind and then fine grain it from there...

BDubCook
  • 488
  • 1
  • 4
  • 15
0

I used Chris Simpson's answer on this thread: SQlite Getting nearest locations (with latitude and longitude)

Thanks everybody.

Community
  • 1
  • 1
Daniel Haviv
  • 1,036
  • 8
  • 16