Giacomo Balli profile picture
Giacomo Balli
The Mobile Guy

Over two decades of experience at your service.
I help business owners make better decisions.

Let's Chat LinkedIn

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.";
    case 2:
        msg += " because your position is unavailable.";
    case 3:
        msg += " because it was taking too long.";

    alert("GPS fail.

"+msg); };

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

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