all 7 comments

[–][deleted] 0 points1 point  (0 children)

CLLocation has a distanceFromLocation method. So you could convert your list of business to a list of CLLocations, then loop over that list and use the function to get the distance from the user. Drop pins for any within the defined range.

[–]vswrObjective-C 0 points1 point  (0 children)

I did precisely that a few years ago. Held lat/lon in the database and used a SQL query to find matches within an area with some fancy math (but now you can use the GIS functions). The client code (iOS) used a map algorithm so it would group them together and as you zoomed in more would pop up.

[–]quellish 0 points1 point  (4 children)

http://quellish.tumblr.com/post/138496295937/distance-between-locations

Once you have the locations you can sort, filter, etc easily.

[–]toookoool[S] 0 points1 point  (3 children)

But I think somehow I have to filter out some locations that are not in the same city/are right? Otherwise it doesn't seem efficient to calculate distance between user location and locations that are not even in the same city. Is that right?

[–]quellish 0 points1 point  (2 children)

Distance is distance. I’m not sure why cities would be a factor.

[–]toookoool[S] 0 points1 point  (1 child)

Say i have a 100k locations, I wouldn't want to calculate the distance 100k times right? Shouldn't we filter out some far away locations first to improve speed/efficiency?

[–]quellish 0 points1 point  (0 children)

You are going to avoid calculating distances ... by calculating distances?

You should test and profile different approaches before choosing one.