Skip to content

stephenlb/geohash-chat-by-proximity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geohashing Chat by Proximity UPDATED

💡 NEW PubNub GitHub repository for New Geo Chat

Use the above link to find the latest Geo Powered Chat. Below is the older version.

Geohashing Chat by Proximity

To connect groups of two or more people by location, you will take lat/long values and reduce the resolution of accuracy, and by doing this you can expand the coverage of proximity. You can use multiple resolutions at once or a fixed resolution.

Get Source Code: GitHub Repository for Geo Chat by Proximity

Geohashing Chat Conversations based on Proximity Zoom Level

Basics of Geo Hashing

Next we'll cover some source code snippet for geo hashing lat/long coords. It is fairly simple to increase the radius of lat/long position by reducing the accuracy of the float values. Using this you can expand the circle and collect a Lat/Long.

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Geo Hash
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function geohash( coord, resolution ) {
    var rez = Math.pow( 10, resolution || 0 );
    return Math.floor(coord * rez) / rez;
}

Acquire Lat Long Chat Proximity Location

Geo Hashing Resolution "Zoom"

"Zoom" levels, basically several different cartesian grids with larger and smaller granularity. Once a Geofencing event fires, you will publish to a set of channels corresponding with each zoom level. Zoom levels are important as that is how we actually construct the link between Geofencing and PubNub. Zoom level is the resolution/de-resolution of the Cartesian coordinates Lat/Long (think X,Y coord). By reducing the resolution of the lat/long coord we can construct a channel name that hits 1 box of the grid. Less resolution means larger the boxes and is required to determine a PubNub Channel that is associated.

// Create Proximity Channel
channel = geohash( pos.latitude, 0 ) + '' + geohash( pos.longitude, 0 );

This will create a very wide circle and generate a channel name used to connect. Next connect to PubNub with this channel name.

// Connect to Proximity Channel
pubnub.subscribe({
     channel : channel,
     message : receive,
     connect : ready,
    presence : presence
});

Acquired Latitude Longitude Chat Proximity Group

Multiplexing 9 Boxes

You will calculate the surrounding squares to extend the taper and radius in a way that provides more accuracy. This will remove the "fencing" effect.

Geo Hashing with PubNub Conclusion

That's it! You simply reduce the resolution of a geo coordinate and use that as a channel name on PubNub. Also check out the browser's navigator.geolocation.getCurrentPosition(...) method to acquire lat/long in a chrome/firefox/ie/opera/mobile/safari browser.

Also checkout the PubNub Connected Car Solution Kit

Geohashing Chat Conversations based on Proximity Nearby

About

Geo Hashing Chat by Proximity to connect two or more users to a group chat.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published