Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

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

  • suselko
  • suselko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 week 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.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 week ago #195507 by DenisChenu
1 : can be done with javascript / jquery : see stackoverflow.com/questions/6092400/is-t...ined-with-javascript
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 .
I don't answer to private message.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 week ago - 4 years 1 week 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.

Code:
<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);
    }
 
    getGPS();
 
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 1 week ago by tpartner.
The topic has been locked.
  • suselko
  • suselko's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 week ago #195528 by suselko
Many thanks both, Tony's script solved the issue.
The topic has been locked.
More
3 years 11 months 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?
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose