Saving GPS coordinates

More
2 years 6 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.
More
2 years 6 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.
Official LimeSurvey Partner - partnersurveys.com
The topic has been locked.
More
2 years 6 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
Attachments:
The topic has been locked.
More
2 years 6 months ago #172314 by tpartner
Replied by tpartner on topic Saving GPS coordinates
Try this for the respective scripts:

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

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.
Official LimeSurvey Partner - partnersurveys.com
Attachments:
The following user(s) said Thank You: DenisChenu, tpervaiz, DavidPausDD
The topic has been locked.
More
2 years 6 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?
Attachments:
The topic has been locked.
More
2 years 6 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
2 years 6 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.
More
2 years 6 months ago - 2 years 6 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.
Official LimeSurvey Partner - partnersurveys.com
Attachments:
Last edit: 2 years 6 months ago by tpartner.
The topic has been locked.
More
2 years 2 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
2 years 2 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
2 years 2 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
2 years 1 day 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.

Start now!

Just create your account and start using Limesurvey today.

Register now