From the course: HTML5: Geolocation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Handling errors

Handling errors - HTML Tutorial

From the course: HTML5: Geolocation

Start my 1-month free trial

Handling errors

Error handling in HTML5 geolocation is simple; it's just a matter of using a separate callback function. Here we have a working copy of 03-errorhandling-start.html, and again I suggest you make a working copy of these and work from that, so that if you need to you can always revert back to your original copy. This is pretty much where we left off from the last lesson. So we have our show_coords function, and that's getting called with this getPosition from the JavaScript, and there is our simple HTML. So the first thing we are going to do is we are going to write our little error handler function, and again this is just very, very simple. And it gets an error object, and that error object has a property called code, which has the error.code. So we are going to use a switch statement. Then we are going to switch on the error.code. And the error object also has these handy constants, so that we don't have to remember the numbers or write the numbers, and we have this nice mnemonic…

Contents