GPS update coordenates

hi,

im trying to build a gps app to detect certain points.

i use this code to update gps lat an lng:

local function updateGPS() Runtime:removeEventListener( "location", locationHandler ) Runtime:addEventListener( "location", locationHandler ) end timer.performWithDelay(3000, updateGPS, 0) Runtime:addEventListener( "location", locationHandler ) 

is there a way to update the lat and lng without removing and creating the runtime?

on device it will not update 3 and 3 seconds…some times takes 10s to update…and worst…the direction and other info sometimes doesn’t update or goes to 0.

regards,

Carlos.

i removed the updateGPS function, just using

Runtime:addEventListener( "location", locationHandler ) 

it will update every second. how can i control the frequency the listener will update? it will consume a lots of battery. the app will be more than 1 hour ON.

the code i provided in the first post, trying to lower the frequency, doesn’t work well.

btw, none work for direction if im stoped it will give me always 0. i guess i need the heading runtime also?

regards, 

carlos.

What are you “polling” for using GPS? Once you get a successful update, can’t you just turn off the polling until you need to check again?

Brent

imagine your walking with the app…and in a certain GPS coordenate…it will tell you what’s that place…and give you more info about it…if you keep moving you will get to the next point, etc…so the gps needs to be active…i can disable it for a couple of minutes while it detect it’s on a spot, but most of the time will be enable.

i already made a demo app with a couple of lines that works fine without removing the runtime…but i wish i could controll the frenquency of the updates so i could save some battery life…the gps data doesnt need to be updated every second…the points are are not that near that needs constant check up.

In that case, how about running your own timer in the app? Make it trigger every 5 minutes or something… and then when it triggers, turn the GPS on for 5-10 seconds, then shut it back off. Next time the timer triggers (like 5 minutes later or whatever), repeat and start detecting GPS.

the other problem i’ve its direction…because in a road you can have 2 spots on each side…it needs to detect if you go one direction of another…i think heading will help in that but i didnt read much about it…the phone needs to pointed parallel to that road? ou it work grabing the phone on any direction?

No, heading should work like a normal compass. Try it out yourself by building and installing the Compass sample app on your phone:

Corona > SampleCode > Hardware > Compass

brent, i tried that system …it’s on my first post…it didnt work…i tried 3s, 5s, 10s, 11s. noone worked like when i doesnt remove the runtime.

if i leave the runtime…first 5s or so…it will not update the gps every second…maybe it’s getting gps postion…after that i will get constant data…every second…if i remove and create…it will have that weird effect…for a few sec it will not work…but when its about to start…it will remove…still even if it will work with more test…i don’t know if it will not consume more battery because removing and creating…makes a new connection consuming more? i can be wrong ofc…it would be a lot easier if i could just object:updateGpsRate(2000) or something…

so heading will not work because in that street if the phone can be picked backwords and it will give me wrong information.  “location” runtime, returns direction, but will only works if i’m moving…that i checked today while walking…and i can turn around the phone that doesnt mather…it will give me the correct direction…the problem…is if the app is used on a bus…and the person only opens the app when it’s stoped on that place…it will not know where whats the direction…because hes stopped…

There’s nothing Corona can do to dictate how fast it takes the device/OS to start checking for GPS response. The hardware itself has to be initiated and detection has to start occurring. I’m also not entirely sure Corona is controlling the 1-second check once the hardware is polling… very likely that’s a system/OS thing as well. Have you searched online for any details on GPS frequency of mobile devices in general?

You’re saying that if I run the Compass sample and flip the phone over, “west” becomes “east” or something? That doesn’t sound right… I guess I need to try that and see what happens. :slight_smile:

if it was for me…i would present the 2 places…and the person choses the one he wants it to learn more about…but the client wants the app to detect the direction he his going or is.

no, what i’m saying in compass…if you turn your device W, the degrees are different than if you turn yor device E…so if they are different i cant just make a rule that there is an object at 200º for example (with 30º ± error) because the phone can be pointing to any direction. he assumes you going where your pointing. but ofc in real life…a client can be pointing to any direction the phone…and moving to another…that i can’t control

*edit* i can do that with the “location” runtime variable direction. but the person needs to be moving to work…if he opens the app on the place it will fail to detect the direction. (direction is 0 stopped)

on android there are variables that can be changed to change GPS work easy:

https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest

here is a post regarding updating gps:

https://stackoverflow.com/questions/26114345/difference-between-locationrequest-setinterval-long-millis-and-locationrequest

reading from google:

https://developer.android.com/guide/topics/location/strategies.html

it will point to here (if i want to change the interval gps updates):

https://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(java.lang.String, long, float, android.app.PendingIntent)

i just learned that i can reduce gps usage in corona using this:

system.setLocationThreshold()

this will help.

i wish some like this could be done for GPS changing the Hz,

system.setGyroscopeInterval()

event.direction on Runtime:addEventListener( “location”, locationHandler ) is giving me different results than compass (smartphone is in the same direction i’m movin. they point to the same north? they should have same values when i’m moving with smartphone pointing to the direction i’m moving (straight ahead), right?

i removed the updateGPS function, just using

Runtime:addEventListener( "location", locationHandler ) 

it will update every second. how can i control the frequency the listener will update? it will consume a lots of battery. the app will be more than 1 hour ON.

the code i provided in the first post, trying to lower the frequency, doesn’t work well.

btw, none work for direction if im stoped it will give me always 0. i guess i need the heading runtime also?

regards, 

carlos.

What are you “polling” for using GPS? Once you get a successful update, can’t you just turn off the polling until you need to check again?

Brent

imagine your walking with the app…and in a certain GPS coordenate…it will tell you what’s that place…and give you more info about it…if you keep moving you will get to the next point, etc…so the gps needs to be active…i can disable it for a couple of minutes while it detect it’s on a spot, but most of the time will be enable.

i already made a demo app with a couple of lines that works fine without removing the runtime…but i wish i could controll the frenquency of the updates so i could save some battery life…the gps data doesnt need to be updated every second…the points are are not that near that needs constant check up.

In that case, how about running your own timer in the app? Make it trigger every 5 minutes or something… and then when it triggers, turn the GPS on for 5-10 seconds, then shut it back off. Next time the timer triggers (like 5 minutes later or whatever), repeat and start detecting GPS.