Reputation: 1621
I have been trying to make a web app that has a certain feature like uber where users can see other users on a map. I read about pubNub (https://www.pubnub.com/) and I saw they have a tutorial that allows you to track movements on a map https://www.pubnub.com/tutorials/javascript/mapping-javascript-tracking/.
They also provide a tool called presence (https://www.pubnub.com/products/presence/) which allows you to see if users have joined your web session or not. I would like to, with presence, to show on a map if people have joined the session or left the session. If they are on the map, I would like the movements to be updated as well.
I am just wondering if someone has used pubNub before to achieve something similar and if so how to go about it?
Upvotes: 4
Views: 2511
Reputation: 6834
https://github.com/pubnub/pubnUber - GitHub Repository
Today we're going to use Phonegap and PubNub to create a simple taxi hailing app. What we'll walk through today is the same technology stack used by Uber, Gett, and other taxi hailing apps. They all work in a similar fashion.
/rider
and /driver
. We're going to start with /driver
.First, we need to set up PubNub. the PUBNUB
variables comes for free from the EON library. The publish_key
and subscribe_key
settings come from your PubNub account.
var channel = "pubnub-taxi-app";
var pubnub = PUBNUB.init({
publish_key: 'demo',
subscribe_key: 'demo'
});
The pubnub
plugs the same pubnub
variable we configured in the first step into EON. This lets us use our own PubNub keys within EON.
Our Mapbox configuration is set and we're ready to send some
Define our PubNub channel.
Subscribe.
pubnub.subscribe({
channel: channel,
message: function(message,env,channel){
if(message == 'hail') {
var pickup = confirm("Someone requested a ride!", "Accept");
if(pickup) {
pubnub.publish({
channel: channel,
message: 'pickup'
});
}
}
}
});
And here is the hail()
function.
var hail = function(argument) {
pubnub.publish({
channel: channel,
message: 'hail'
});
alert('Waiting for driver...');
};
Upvotes: 3