Getting GPS coordinates and saving to database

Mehr
2 Monate 1 Woche her #183247 von AnnalieF
I am trying to get GPS coordinates on page startup and saving that to the SQL database. The code that I am using, is as follows:
$(document).on('ready pjax:complete',function()
  {
		// Get question
		var q2ID = '{QID}';
		var q2 = $('#question'+q2ID);
 
		function getGPS() {
			if (navigator.geolocation)
      {
				navigator.geolocation.getCurrentPosition(showGPS, showError, { enableHighAccuracy: false, maximumAge: 0, timeout: 30000 } );
        //alert("Geolocation is not enabled");
			}
      else
      {
				//alert("Geolocation is enabled");
        $('input.text', q2).val('Geolocation is not enabled');
			}
		}
 
		function showError(error)
    {
			//alert('GPS Error: '+error.code+', '+error.message);
      {
                switch (error.code) {
                    case error.TIMEOUT:
                        //alert("The request to get user location has aborted as it has taken too long");
                        $('input.text', q2).val('Request timeout');
                        break;
                    case error.POSITION_UNAVAILABLE:
                        //alert("Location information is not available");
                        $('input.text', q2).val('No location information');
                        break;
                    case error.PERMISSION_DENIED:
                        //alert("Permission to share location information has been denied");
                        $('input.text', q2).val('Permission denied by user');
                        break;
                    default:
                        //alert("An unknown error occurred.");
                        $('input.text', q2).val('Unknown error');
                }
            }
		}
 
		function showGPS(position)
    {
			$('input.text', q2).val(position.coords.latitude+', '+position.coords.longitude);
		}
 
    getGPS();
 
	} );
</script>

The code seems to work and writes the coordinates into a short free text field, but it only works if the Google Maps button is selected in the Location -> Use mapping service section. But I don't want to display the map, I only want the coordinates. Is there any way to do this?

Also, the displayed coordinates are not saved in the database. I have tried to set the value of another field based on the value of the field in which the coordinates are displayed, but no text is displayed in the field. The code that I am using in the source section of the group is:
<script type="text/javascript" charset="utf-8">
 
$(document).ready(function() {
 
 $('#answer929736X13X17').val('{INSERTANS:929736X12X18}');
 
});
 
</script>

The latter code does work if I write the values of another short free text field, that only contains regular text, to this field.

I have already looked at the answers in the following topic:
Saving GPS coordinates

My lime survey details are: Version number: 3.17.0, build number: 190402

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

LimeSurvey Partners
Mehr
2 Monate 4 Tage her #183318 von AnnalieF
I replaced the way the coordinates and error feedback is assigned to the field, e.g.

$('input.text', q2).val(position.coords.latitude+', '+position.coords.longitude);

replaced with
$('#answer929736X12X24').val(position.coords.latitude+', '+position.coords.longitude);

and now both problems are solved.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha