Giacomo Balli profile picture
Giacomo Balli
Complex decisions. Clear thinking.

Independent advice for business owners navigating technology decisions, challenges and opportunities.
Fluent in business. Grounded in technology. Paid only by you.

Let’s Talk It Through LinkedIn

Building technology products since 2010 · 100+ apps

Reasons why GPS failed

This code sample will allow you to show a message to the user regarding why you were unable to retrieve their GPS data.

var gpsWin = function (position) {
    console.log('GPS', position);
    alert("Current device GPS accuracy is " + parseInt(position.coords.accuracy) + "m.");
};
var gpsFail = function (e) {
    var msg = "Your device was unable to provide GPS coordinates";
    switch (e.code) {
    case 1:
        msg += " because you didn't allow it.";
        break;
    case 2:
        msg += " because your position is unavailable.";
        break;
    case 3:
        msg += " because it was taking too long.";
        break;

    }
    alert("GPS fail.

"+msg); };

Directions:
- add the success and error callback to your project.
- call navigator.geolocation.getCurrentPosition(gpsWin, gpsFail);

Note:
This snippet focuses on iOS development. Make sure to verify/adapt any vendor prefixes. Back to main listing.

Published: Sun, Jan 10 2016 @ 18:51:54
Back to Blog