CSentry Android Smartphone; GPS function and button
-
- Posts: 8
- Joined: April 23rd, 2014, 9:59 am
CSentry Android Smartphone; GPS function and button
Hi,
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?
Thanks a million!
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?
Thanks a million!
-
- Posts: 1792
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: CSentry Android Smartphone; GPS function and button
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()
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 add the button using this code: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;
userbar(add button,"Get GPS Reading",GetGPS);
-
- Posts: 8
- Joined: April 23rd, 2014, 9:59 am
Re: CSentry Android Smartphone; GPS function and button
OK, thank you so much! I will work on it tomorrow and let you know if it resolves the problem (if not, I'll post the logic here too).
ps. sorry for the late reply (working in the field can get crazy at times )
ps. sorry for the late reply (working in the field can get crazy at times )
-
- Posts: 8
- Joined: April 23rd, 2014, 9:59 am
Re: CSentry Android Smartphone; GPS function and button
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;?
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;?
-
- Posts: 1792
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: CSentry Android Smartphone; GPS function and button
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:
http://www.csprousers.org/beta/MetroSurvey.7z
http://www.csprousers.org/beta/MetroSurvey.7z
PROC METRO_SURVEY_QUEST
preproc
userbar(clear);
userbar(add button,"Find Closest Metro Stations",findClosestMetroStations);
userbar(show);
preproc
userbar(clear);
userbar(add button,"Find Closest Metro Stations",findClosestMetroStations);
userbar(show);
-
- Posts: 8
- Joined: April 23rd, 2014, 9:59 am
Re: CSentry Android Smartphone; GPS function and button
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?
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?
-
- Posts: 1792
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: CSentry Android Smartphone; GPS function and button
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.
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.
-
- Posts: 8
- Joined: April 23rd, 2014, 9:59 am
Re: CSentry Android Smartphone; GPS function and button
Ah okay, that explains it . I'll soon buy another phone with a GPS receiver and try again (apparently most phones in Burundi don't have it ) Thanks!
-
- Posts: 8
- Joined: April 23rd, 2014, 9:59 am
Re: CSentry Android Smartphone; GPS function and button
Hi,
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?
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?
Re: CSentry Android Smartphone; GPS function and button
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?
Josh
Have you tried other GPS applications besides CSPro to see if it as a problem with CSPro or with the phone itself?
Josh