The community forums are in BETA and closed to the public.

Geolocation Chatrooms

I'm trying to work out how to go about setting up multiple chat rooms based on Geolocation. I've been playing around with I am wondering if someone could point me in the right direction. Has anyone done this before or got an example of how you would go about it. Cheers

First of all, you need to get a user location. You can just use JavaScript geolocation API to get the location:

var lat, lon, channel;
navigator.geolocation.getCurrentPosition(function(position) {
  lat = position.coords.latitude;
  lon = position.coords.longitude;

this give you the user's location in lat, lon.

Then you can create a proximity channel using the geohash function (see the github page you're referring to) by passing the geo coordinates.

channel = geohash( lat, 0 ) + '' + geohash( lon, 0 );

I also created a CodePen:

Hello, I am also trying to create geo located chatrooms. I've looked at the Github and I was wondering how is the "resolution" related to "distance". I would like to add a menu in my chat where the user can decide: "I would like to chat with people at 5km / 20 km / 50 km / 500 km / ..... from my location" and make him subscribe to a geo chat room after selection has been made. Is there a way to know the radius in km of the "geo-fencing" when we set the resolution?

Thanks for the help!

S_bastienLoix, The resolution is related to the precision- the higher the resolution, the smaller the grid gets. - i.e. the area is more pinpointed.

Take a look at the demo I used on CodePen (URL is shown above). I used the resolution 0 (as default), which gives you a largest grid. For example, PubNub office location sits on the geohash, 37-123, which grid size is approx 111km x 111km (circumference of the earth 40,075km/360deg).

If you switch the resolution to 1, the geohash becomes 37.7-122.4. The precision gets higher, and the grid size is reduced by 10-fold.

So do your math ;-)

Or in your case, it is easier to just calculate radius from coords!

Hi tomomi, Sorry for the late answer, I didn't receive email alert of your solution and had to switch to some other part of the project... I am now back to it and will try to build the chat geo feature based on what you comment (and at the same time undust my trigonometry math book ;) Thank you!

Comments to this discussion are now closed!