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.
- Install phonegap on the CLI.
- Clone this repository locally.
- The repo contains two directories
/riderand/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 pubnubu 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...');
};