Geo tagging

mail@pastecode.io avatar
unknown
javascript
2 months ago
2.3 kB
5
Indexable
Never
fetchGeoLocation: function(component, event, helper) {
        var geoObj = {};
        var errorReason = "";
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(
                //success handler
                function(position) {
                geoObj.latitude = position.coords.latitude;
                geoObj.longitude = position.coords.longitude;
                console.log('location is captured.');
               /* var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Info",
                    "type": "Info",
                    "message": "Saving location"
                });
                toastEvent.fire();*/
                helper.updateGeoLocation(component, event, helper, geoObj);
            	}, 
                //error handler
                function(error) {
                switch (error.code) {
                    case error.PERMISSION_DENIED:
                        console.log("User denied the request for Geolocation.");
                        errorReason = $A.get("$Label.c.Check_In_Permission_Denied");
                        break;
                    case error.POSITION_UNAVAILABLE:
                        console.log("Location information is unavailable.");
                        errorReason = $A.get("$Label.c.Check_In_Position_Unavailable");
                        break;
                    case error.TIMEOUT:
                        console.log("Unable to capture Geolocation. Please ensure location services are turned on.");
                        errorReason = $A.get("$Label.c.Check_In_Timeout");
                        break;
                    case error.UNKNOWN_ERROR:
                        console.log("An unknown error occurred.");
                        errorReason = $A.get("$Label.c.Check_In_Unknown_Error");
                        break;
                }
                helper.showToast(component, event, 'Error', errorReason);
            },
            //set timeout
            {timeout:3000}
            );
        } else {
            errorReason = $A.get("$Label.c.Check_In_Not_Supported");
            helper.showToast(component, event, 'Error', errorReason);
        }
    },
Leave a Comment