Welcome to the LimeSurvey Community Forum

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

Saving GPS coordinates

More
5 years 7 months ago #172306 by tpervaiz
Replied by tpervaiz on topic Saving GPS coordinates
I used this code which is working perfectly in survey however the coordinates are not showing in response or survey report..Is there anything else I have to do?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #172310 by tpartner
Replied by tpartner on topic Saving GPS coordinates
What LimeSurvey version are you using?

Can you attach an export (.lss) of a small sample survey?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 7 months ago #172313 by tpervaiz
Replied by tpervaiz on topic Saving GPS coordinates
the version is Version 3.14.2+180807

I am able to get GPS coordinates in both ways Automatically as well as Push button but the problem is the coordinates are not showing in responses and reports

Please see the lss in attachment

Thanks in advance
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #172314 by tpartner
Replied by tpartner on topic Saving GPS coordinates
Try this for the respective scripts:

Code:
<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>

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

Sample survey attached:

File Attachment:

File Name: limesurvey...2762.lss
File Size:19 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu, tpervaiz, DavidPausDD
The topic has been locked.
More
5 years 7 months ago #172315 by tpervaiz
Replied by tpervaiz on topic Saving GPS coordinates
GPS coordinates are not even showing in survey itself by using the script provided by you

Do I need more workaround?
The topic has been locked.
More
5 years 7 months ago #172316 by tpervaiz
Replied by tpervaiz on topic Saving GPS coordinates
Its working now,, I copied half script

Thanks alottttt
The topic has been locked.
More
5 years 7 months ago #172318 by tpervaiz
Replied by tpervaiz on topic Saving GPS coordinates
Is it possible to hide the question and get the GPS Coordinates in reports only?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago - 5 years 7 months ago #172320 by tpartner
Replied by tpartner on topic Saving GPS coordinates
Assign a CSS class "hidden". But, note that the browser will likely still ask whether the respondent wants to allow location tracking.


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 7 months ago by tpartner.
The topic has been locked.
More
5 years 3 months ago #178051 by hmd_bakhshi
Replied by hmd_bakhshi on topic Saving GPS coordinates
Hi
I copy this code to my first question but it doesn't work!
The topic has been locked.
More
5 years 3 months ago #178052 by tpervaiz
Replied by tpervaiz on topic Saving GPS coordinates
Copy below script in first question's source

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

// Identify this question
var q1ID = '{QID}';
var q1 = $('#question'+q1ID);

// Hide this question
q1.hide();

function getGPS() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showGPS, gpsError);
} else {
$('input.text', 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);
}

getGPS();

});
</script><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><script type="text/javascript" charset="utf-8">

$(document).on('ready pjax:scriptcomplete',function(){

// Identify this question
var q1ID = '{QID}';
var q1 = $('#question'+q1ID);

// Click event for the button
$('.gpsLink').click(function(){
getGPS();
});

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);
}

});
</script>


Also please follow the below instructions

- type of question must be short text
- In location panel select Google Maps
- Type in CSS class(es) : hidden
The following user(s) said Thank You: hmd_bakhshi
The topic has been locked.
More
5 years 3 months ago #178053 by hmd_bakhshi
Replied by hmd_bakhshi on topic Saving GPS coordinates
thanks alot. I think my deadly mistake was that I do not turn on the google map in the local menu! it's work perfectly
The topic has been locked.
More
5 years 2 weeks ago #181156 by DavidPausDD
Replied by DavidPausDD on topic Saving GPS coordinates
Using this script, how can I move the map to the position I get to correct it if necessary?
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose