do not advance to next question until respondent allows to be geolocated

2 months 2 weeks ago #195479 by suselko
I have a mobile phone-based survey with a hidden question that stores the respondent's geographical coordinates. A system window pops up asking the respondent if they allow to be geolocated. It works fine on iPhones as the respondent has to to 'allow' or 'disallow' before they can tap on LimeSurvey's 'Next' button. But it doesn't work well on Android phones as the respondent can just tap on the 'Next' button without doing anything to that pop-up window. When this is done, the survey proceeds to the next question and the pop-up window disappears. Any ideas how I could either (1) make the 'Next' button inactive until the respondent 'allows' or 'disallows' geolocation; or (2) force the pop-up window to stay on screen until 'allow' or 'disallow' is tapped (even if LimeSurvey has moved on to the subsequent questions). Basically anything that addresses the problem! The survey group file is attached. Many thanks.

Please Log in to join the conversation.

LimeSurvey Partners
2 months 2 weeks ago #195507 by DenisChenu
1 : can be done with javascript / jquery : see
2 : it's a browser system i think, can not be updated.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

2 months 2 weeks ago - 2 months 2 weeks ago #195519 by tpartner
suselkois already using the error callback in the getCurrentPosition() function so maybe something like this.

Note that there may be a delay as the getCurrentPosition() function fires so you may want to incorporate a loading graphic of some sort.

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
		// Identify this question
		var q1ID = '{QID}';
		var q1 = $('#question'+q1ID);
		// Disable the "Next" button
		$('#ls-button-submit').prop('disabled', true);
		function getGPS() {
			if (navigator.geolocation) {  
				navigator.geolocation.getCurrentPosition(showGPS, gpsError);
			} else {  
				$('input.text', q1).val('No GPS Functionality');
				$('input:hidden[id^="answer"]', q1).val('No GPS Functionality');  
		function gpsError(error) {
			alert('GPS Error: '+error.code+', '+error.message);
		function showGPS(position) {
			$('input.text', q1).val(position.coords.latitude+', '+position.coords.longitude);
			$('input:hidden[id^="answer"]', q1).val(position.coords.latitude+';'+position.coords.longitude);
			// Enable the "Next" button
			$('#ls-button-submit').prop('disabled', false);

Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner -
Last edit: 2 months 2 weeks ago by tpartner.

Please Log in to join the conversation.

2 months 2 weeks ago #195528 by suselko
Many thanks both, Tony's script solved the issue.

Please Log in to join the conversation.

2 months 2 days ago #196273 by Andrewsss
Is it possible if user by accident click block location, add one more button with click and survey asking again user location?

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now