Reputation: 4632
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?
Upvotes: 1
Views: 474
Reputation: 934
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.
Upvotes: 1
Reputation: 113
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
Upvotes: 0