Hacker News new | ask | show | jobs
Ask HN: Could any iOS Developer Give me some pointers?
2 points by markcrazyhorse 4183 days ago
I'm quite new to iOS Development and wanna get stuck right in :) I'm just looking to find the best practice for this:

I know I can use CLLocationManager to get the users location but I want to create an app that does this:

User logs in > app checks web server for online users in specified radius in miles/feet of the current users phone > displays users.

What is the best way to go around this? much appreciated for all your help.

2 comments

I think stackoverflow is better for this specific question.

Having said that most databases (on the backend) have spatial extension where you can run queries like 'where inside(point,geometry)'. So you create a bounding box or circle around the user, then run a query. That's faster than calculating distances between all users. The databases have special indices for geographic lookup. Both point and geometry probably need to be specified in WKT format. http://www.gaia-gis.it/spatialite-2.1/SpatiaLite-manual.html http://docs.mongodb.org/manual/applications/geospatial-index...

Assuming you have the coordinates for the each online user, iterate that collection, create a CLLocation object from the coordinate data, and check that object against CLLocation method distanceFromLocation with a radius value.

https://developer.apple.com/library/ios/documentation/CoreLo...:

Yes. When the user opens the app I will get their current location and add it to a column in the database 'currentLocation' Then I will query the database like so: select * from users where userOnlineStatus = 'online' and currentLocation = ""; <- That is what I would want to do. Its just calculating the distance so that not all random users are showing up.
Also as @mtmail mentions, the better path for this is probably not on the device itself. It would get expensive where N number of users is really high. Perhaps at the service layer, send the device location to the service, and have the service return the nearby users.