Location gukhg gfyjgjg

I see some pages which are able to read user location. What is your prefered method to read user location in SC App ?

1 Like

I usually put in the the header and save the result using AJAX

/* get GPS location */
getLocation();
setInterval(function() {
    getLocation();
}, 300000);
  
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    }
}
  
function showPosition(position) {
var user = "{SC_USERNAME}";
$.ajax({
    url: '../Log_GPS/index.php',
		type: 'POST',
		data: 'Lat=' + position.coords.latitude + '&Long=' + position.coords.longitude + '&Acc=' + position.coords.accuracy + '&User=' + user,
		success: function(data){
		     /* alert("User:" + user + " - Latitude: " + position.coords.latitude + " - Longitude: " + position.coords.longitude + " - Accuracy: " + position.coords.accuracy); */
		},
		error: function(data) {
		     /* alert("Problème de sauvegarde"); */
		}
});
}
2 Likes

as far as i know this is now a simple task, you should look for it on HTML Geolocation API

one thing about it is that you can only use this function (i am telling you this by memory, please chek for it on internet) on a server with a secure sertificate, this is for the safty of your users, on the other hand you can use it on your own computer as localhost, your browser will “undertand” that it is only a test envairoment

(there is also some apis can help you with this sort of things and make your life easier)
bet regards

fer

That is exactly what i am proposing + a way to save it. :slight_smile:

1 Like

By looking at this code I am a bit confused. So what values aou are sving ? where is your storage variable ?

This example will send [Lat], [Long], [Acc], and [User] to a blank application call Log_GPS