Welcome to the LimeSurvey Community Forum

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

Show the location of survey takers with Google Maps Location feature.

  • darliv
  • darliv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago - 1 year 10 months ago #241671 by darliv
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.6.10+230313
Survey theme/template: fruity

==================
Hello Everyone!!
I have done the part where i add a question as "free short text",
in settings choose Location "Google Maps" with my API Key that is saved in Global Settings, and
get the current GPS location of a survey taker.

Now the problem is that the default zoom and focus coordinates are always in Hamburg, i want the map to focus and zoom in my GPS Location not just 
to fill the input field with my coordinates.
And also i want to save my city in Responses if possible.

Thank you!
Last edit: 1 year 10 months ago by darliv.

Please Log in to join the conversation.

  • darliv
  • darliv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #241673 by darliv
The part that shows GPS :

<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var q1ID = '{QID}';
    var q1 = $('#question'+q1ID);
 
    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);
    }
 
    getGPS();
 
  });
 

</script>

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose