Get latitude/longitude and stop location runtime event

Just submitted it again and got this message on submit “Thank you for your submission. We will do our best to evaluate your case and respond as quickly as possible.”, but again no automated email. 

Check your spam folder?

Rob

nothing. can I attach the file here?

That won’t get the project to engineering.  Do you know what you titled the bug?  Give me something to search on?  I even tried to search for your email address and didn’t find anything. 

Rob
 

I believe it was titled something along the lines of “GPS location firing constantly on device”

Are you using the “Report a Bug” link at the top of the page?  That message doesn’t match up with what our bug tracker seems to output.  I’m not finding anything open, filed in the past month or so with GPS and location in the submission.

Rob

Ya. Should I try the email method?

We just want to make sure you’ve not found a bad link.  Email support@coronalabs.com with your project attached and your description in the email.  Make the subject what you want the title of the bug report to be.  That will work too.

Rob

Email sent. case # 34185

Thanks for getting this filed.

Rob

Engineering has looked at this, and it seems like it’s going to be difficult to do and could create regression issues.  They suggest the following:

Instead of doing:

local function listener(event)     Runtime:removeEventListener("location", listener) end Runtime:addEventListener("location", listener)

you can do:

local object = {} object.location = function(event)     Runtime:removeEventListener( "location", object) end Runtime:addEventListener("location", object)

which is known to work.

Rob

This is great news!!! Can this somehow also be used to turn gps off while mapviewer is in use? If I only want to provide mapviews and not plot user location on the map etc it is a waste of battery juice to keep the gps running. Any ideas on whether this trick can help there? Thanks

Filed a bug relating to removing a mapView, and the GPS remains permanently on (during suspend). Case 34342.

Same problem here, can’t seem to be able to get lat and lng only once.

I would love to get an answer to this as well. Currently this issue causes unnecessary battery drain. There must be a way around this. Thanks for your help.

It is because you can’t remove a listener from inside a listener. 

try to put your removeListener call in a timer.performWithDelay closure to see if it helps.

 timer.performWidthDelay( 10, -- 10 ms delay, just to "get out" of the listener scope function(e) Runtime:removeEventListener("location", myListener) end )
local updateLocation = function() local function locationHandler(event) if event.errorCode then print(" ERROR : " .. tostring( event.errorMessage ) ) else print(" LAT : "..event.latitude..", LONG : "..event.longitude) end Runtime:removeEventListener( "location", locationHandler ) end Runtime:addEventListener( "location", locationHandler ) end

Can confirm this is still a bug on all device. The removeEventListener isn’t firing off, other than on the Corona Simulator.

We would need an simple app that shows this problem.  We need a complete sample app (main.lua, your build.settings and your config.lua that’s causing the issue) in a zip file.  Click on the “Report a Bug” link at the top of the page.  When you get the email confirmation, please post the bug # back here as a reference.

Once we see the code, we can help try and figure this out or get it to engineering if it’s a bug.

Rob

Sent in a zip a few days ago and still no email confirmation.