Skip to content

Instantly share code, notes, and snippets.

@ToeJamson
Created September 2, 2015 18:33
Show Gist options
  • Select an option

  • Save ToeJamson/6dab18ab1730ac7778eb to your computer and use it in GitHub Desktop.

Select an option

Save ToeJamson/6dab18ab1730ac7778eb to your computer and use it in GitHub Desktop.
Vehicle Tracking on Realtime Maps
var drivers = [
{ latlng: [30.370375, -97.756138] },
{ latlng: [30.323118, -97.739144] },
{ latlng: [30.302816, -97.699490] },
{ latlng: [30.293479, -97.742405] },
{ latlng: [30.250337, -97.754593] },
{ latlng: [30.236689, -97.762730] }
];
<script type="text/javascript" src="http://pubnub.github.io/eon/lib/eon.js"></script>
<link type="text/css" rel="stylesheet" href="http://pubnub.github.io/eon/lib/eon.css" />
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiaWFuamVubmluZ3MiLCJhIjoiZExwb0p5WSJ9.XLi48h-NOyJOCJuu1-h-Jg';
var map = L.mapbox.map('map', 'ianjennings.l896mh2e');
var channel = 'pubnub-mapbox';
var tacos = new pubnub_mapbox({
map: map,
channel: channel,
init: init
});
//////////////
function init() {
var point = {
latlng: [37.370375, -97.756138]
};
var pn = PUBNUB.init({
publish_key: 'demo'
});
setInterval(function(){
var new_point = JSON.parse(JSON.stringify(point));
new_point.latlng = [
new_point.latlng[0] + (getNonZeroRandomNumber() * 0.1),
new_point.latlng[1] + (getNonZeroRandomNumber() * 0.2)
];
pn.publish({
channel: channel,
message: [new_point]
});
}, 500);
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment