Usually on similar apps the messages go to their servers (over 3/4G) along with your location info, and then they re-route it back to all the users whose reported location is close to yours.
An exception was FireChat, which built a mesh network using the Bluetooh & Wifi-based connectivity API provided by iOS called "Multipeer Connectivity Framework", so you could talk to someone far away as long as there were other users between you, which served as routers.
You could just grab user location and populate it in a db. Use a proximity search to see which users you see and see you.
You could also break things down by geofence, but that would work better for a city chat since there would need to be overlapping fences otherwise you could be next to someone and not see their messages.
There are other ways to do it, but if you are going to use Internet connectivity, that's the simplest I believe.