I've been trying to create a button for GPS in the Android version of CSentry (on a smartphone), but I haven't yet succeeded to do so. What I would like is to create this button and maybe even link it to latitude and longitude variables (items) in the survey, so it's automatically filled out. Could someone explain to me how I could best to this? I've been trying to modify/copy/paste the logic described in the manual/the new beta update/and the metro survey, but it still doesn't seem to work. I know I'm not really an expert on creating lots of logic in the surveys (usually just error messages and skipping questions), so maybe someone here could help me?
You might want to post your code here so that we can look at it and figure out why it might not be working. In general, you could do something like this:
function GetGPS()
ifgps(open) andgps(read,120) then
LATITUDE = gps(latitude); // assign to variables in the dictionary LONGITUDE = gps(longitude);
else errmsg("There was an error reading the GPS coordinates.");
So just a question: if you put this code in the global proc, and you have two variables (LONGITUDE and LATITUDE) somewhere in your dictionary (and not in your form), it should work? If I paste the logic of the function to the global proc, it compiles well (not anywhere else). But I cannot seem to compile if I add the button logic to it...
So this compiles, but doesn't do anything in the application:
PROC GLOBAL
function GetGPS()
if gps(open) and gps(read,120) then
LATITUDE = gps(latitude); // assign to variables in the dictionary
LONGITUDE = gps(longitude);
else
errmsg("There was an error reading the GPS coordinates.");
endif;
gps(close);
end;
and then you can paste the logic of the button before end;?
You'll likely want to add the button in the preproc of your program. That proc's name will end with _FF. Or you can add it in the preproc of the level. That's how it was done in the sample application:
Thanks! I was finally able to add the button to the questionnaire
Unfortunately, it still gives me an error message when reading the coordinates. I read somewhere that this could also be due to the language settings? (currently, it's set to French). Also, does it matter where you have your longitude and latitude variables in your dictionary? I've just added them to the dictionary in one level of the questionnaire and didn't add them to the form itself (so it doesn't appear on the questionnaire, as I want it to be filled out automatically: not only to show the location of the household, but also as a check on the enumerator). Last, if the phone doesn't have a gps function, is it still able to find the coordinates through the network/internet?
What error message are you getting when you run the gps? I've tested received GPS coordinates on a French device and it worked for me.
You must have a GPS receiver to get coordinates. While a cell network can approximate your location, we don't have access to this data from within the CSEntry application.
so I got a new phone with a gps receiver, but it still gives me an error message (it's the one I assigned to it when it cannot read the coordinates: "Message (-11) There was an error reading the GPS coordinates"). I let it read the coordinates for 120 seconds, so I don't understand why it's not working. Anyone else has this problem?
Are you testing this outside where there is an unobstructed line of sight between the phone and the sky? If there is something between the phone and the satellites GPS will often fail.
Have you tried other GPS applications besides CSPro to see if it as a problem with CSPro or with the phone itself?