25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Download from Wow! eBook <br />

232<br />

CHAPTER 9 ■ USING THE <strong>HTML</strong>5 WEB STORAGE API<br />

// reference to the Web Socket<br />

var socket;<br />

var lastLocation;<br />

function updateSocketStatus(message) {<br />

document.getElementById("socketStatus").inner<strong>HTML</strong> = message;<br />

}<br />

function updateGeolocationStatus(message) {<br />

document.getElementById("geoStatus").inner<strong>HTML</strong> = message;<br />

}<br />

function handleLocationError(error) {<br />

switch(error.code)<br />

{<br />

case 0:<br />

updateGeolocationStatus("There was an error while retrieving your location: " +<br />

error.message);<br />

break;<br />

case 1:<br />

updateGeolocationStatus("The user prevented this page from retrieving a<br />

location.");<br />

break;<br />

case 2:<br />

updateGeolocationStatus("The browser was unable to determine your location: " +<br />

error.message);<br />

break;<br />

case 3:<br />

updateGeolocationStatus("The browser timed out before retrieving the location.");<br />

break;<br />

}<br />

}<br />

function loadDemo() {<br />

// test to make sure that Web Sockets are supported<br />

if (window.WebSocket) {<br />

}<br />

}<br />

// the location where our broadcast WebSocket server is located<br />

url = "ws://websockets.org:7999/broadcast";<br />

socket = new WebSocket(url);<br />

socket.onopen = function() {<br />

updateSocketStatus("Connected to WebSocket race broadcast server");<br />

}<br />

function updateLocation(position) {<br />

var latitude = position.coords.latitude;<br />

var longitude = position.coords.longitude;<br />

var timestamp = position.timestamp;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!