

Ask HN: Could any iOS Developer Give me some pointers? - markcrazyhorse

I&#x27;m quite new to iOS Development and wanna get stuck right in :) I&#x27;m just looking to find the best practice for this:<p>I know I can use CLLocationManager to get the users location but I want to create an app that does this:<p>User logs in &gt; app checks web server for online users in specified radius in miles&#x2F;feet of the current users phone &gt; displays users.<p>What is the best way to go around this? much appreciated for all your help.
======
mtmail
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://www.gaia-gis.it/spatialite-2.1/SpatiaLite-manual.html)
[http://docs.mongodb.org/manual/applications/geospatial-
index...](http://docs.mongodb.org/manual/applications/geospatial-indexes/)

------
subv3rsion
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...](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/index.html#//apple_ref/occ/instm/CLLocation/distanceFromLocation):

~~~
markcrazyhorse
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.

