Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Get latitude/longitude and stop location runtime event
Started by contact551 Apr 07 2014 12:29 PM

34 replies to this topic
[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

Thanks for getting this filed.

 

Rob



[TOPIC: post.html]
#27

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

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


[TOPIC: post.html]
#28

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

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



[TOPIC: post.html]
#29

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

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



[TOPIC: post.html]
#30

raremedia

[GLOBAL: userInfoPane.html]
raremedia
  • Observer

  • 14 posts
  • Corona SDK

Not being able to remove a listener from inside a listener function is a serious bug that is far bigger than the scope of Maps and location, it needs to be fixed.



[TOPIC: post.html]
#31

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

Have you tried to put the remove inside of a short timer.performWithDelay()?  Perhaps 10ms would do.

 

Rob



[TOPIC: post.html]
#32

raremedia

[GLOBAL: userInfoPane.html]
raremedia
  • Observer

  • 14 posts
  • Corona SDK

Unrelated timers are not a fix, if the location request takes longer than 10 seconds and the code isn't catching the exception (which it shouldn't have to) it will cause a potentially app breaking bug.

Your workaround works perfectly assuming you don't need the event which isn't passed though in build 2520, instead you get a function?



[TOPIC: post.html]
#33

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

Sometimes trying to remove a listener inside it's self won't work because the function is still running.  The timer lets the function return and complete it's processing then a few milliseconds later, you can remove the handler.



[TOPIC: post.html]
#34

raremedia

[GLOBAL: userInfoPane.html]
raremedia
  • Observer

  • 14 posts
  • Corona SDK

That still doesn't account for cases (which I've experienced) that the function doesn't execute inside the expected time window which results in the performWithDelay call failing and not removing the runtime listener.

 

If the remove can't be executed while the listener function is still executing, we need to be able to 'queue' or set a 'finished event' callback so that the listener can be removed immediately after the function is complete without guessing in milliseconds as to when the function 'should' be finished.

I've tried using closures and tables to do this myself but none of my or your workarounds/fixes are a complete solution (so far.)

 

I understand that technical limitations exist but this isn't an advanced feature, just about any modern language (even js) has this ability.



[TOPIC: post.html]
#35

henrik5

[GLOBAL: userInfoPane.html]
henrik5
  • Contributor

  • 251 posts
  • Corona SDK

Sometimes trying to remove a listener inside it's self won't work because the function is still running.  The timer lets the function return and complete it's processing then a few milliseconds later, you can remove the handler.

 

If you update this and any similar code samples doing so in the docs, I think you'd make a bunch of threads unnecessary! At least that link is where I went first thing.

 

Don't forget to include the forward declarations before the two recurrent functions! At least it wouldn't resolve the matter for people looking at the docs if you didn't, since it's the main cause of the difference in handling of the lua file on IOS 7.1.




[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]