Thanks for that suggestion Robert. I couldn't really find a good way to check to see if location services are enabled on a mobile device. It seems that simply using the if statement from above does nothing. Here is what I came up with and it works so-so, but is susceptible to false error messages since it relies on the phones connection and can time out. My reasoned that if I attempted to get the current latitude when the widget loads and it failed, I could assume that the devices location services are not enabled. I think the best method to test for this would be to query the phone settings, but I don't know how you would go about doing that especially since every device is different.
if (window.appInfo.isRunInMobile) {
var content = this.nls.noGPSMobileContent;
function displayMessages(msg) {
if (this.widgetErrorNode) {
domAttr.set(this.widgetErrorNode, "innerHTML", msg);
}
showMessage(msg);
}
function showMessage(msg) {
var alertMessage = new Message({
message: msg
});
alertMessage.message = msg;
}
var latitude = null;
navigator.geolocation.getCurrentPosition(function (position) {
latitude = position.coords.latitude;
console.log("latitude", latitude);
}, function (error) {
switch(error.code) {
case error.PERMISSION_DENIED:
displayMessages("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
displayMessages("Location information is unavailable.");
break;
case error.TIMEOUT:
displayMessages("The request to get user location timed out. Make sure your location services are enabled");
break;
case error.UNKNOWN_ERROR:
displayMessages("An unknown error occurred.");
break;
}
}, {
timeout: 10000,
enableHighAccuracy: true
});
}