1

For my iPhone app, I have gained user's location in a variable userLocation and I am updating it continuously using CLLocationManager didUpdateLocations method.

In my parse database, I have thousands of stored locations.

My question is what would be the most efficient way to continuously compare/tell if any of those parse db locations are within 100 meters of user's current location?

My current approach is to go through the array of database locations each time user's location changes; calculate distance from current location and tell if distance is less than 100 meters BUT as the location changes continuously, this will be heavy on processor and battery. Any suggestions?

jww
  • 97,681
  • 90
  • 411
  • 885
Kashif
  • 4,642
  • 7
  • 44
  • 97
  • I don't know if this is the most efficient, but this is how I did it: http://stackoverflow.com/questions/29267438/location-alerts-using-core-data-to-get-around-clregion-20-region-cap/29286525#29286525 – Adrian Mar 27 '15 at 20:47
  • 2
    Perhaps you should send the user's location from the device to Parse and tell it to run the query against the data (see http://stackoverflow.com/a/24879278/467105) rather than bringing all the other location data to the device. Keep track of the last time the query was done and only call it again when the user's location changes by X meters or the previous query was more than N minutes ago. –  Mar 27 '15 at 21:21

2 Answers2

1

you can combine Anna's idea (see in the comment), by keep changing the X or N value, according to user's movement speed.

if user are walking, than you just have to perform the next query for a longer time. but if user are using bike, for example, the next query should be more faster.

Gibran
  • 934
  • 2
  • 8
  • 19
0

I would comment, but don't have rep.. Anyway, You could breakdown the locations into a tree type structure to remove half of the locations at each iteration - depending on where your locations are you could use ordnance grid squares or if not, something a little smaller. That way you only search a subset of locations which are reasonably close..? E.g Quad Trees

Paul Reed
  • 113
  • 14