[Android]
I seem to be getting a lot of location events, even if I ask for my location only once.
I do:
myMap = native.newMapView (200, 200, 200, 200)
myMap.isVisible = false
Runtime:addEventListener ("location", e_run_location)
and without any calls of any kind to any map APIs, I get dozens of calls to e_run_location within about two minutes (all with a parameter which is a table of the format returned by getUserLocation).
(The Android phone is sitting on my desk … of course, I can’t say it “isn’t moving” because of normal location jitter.)
Is this normal?
Should I do a removeEventListener after I get my location?
E.g., do:
Runtime:addEventListener ("location", e_run_location)
where = myMap:getUserLocation () -- trigger a request for location now
…
function e_run_location () -- handler for location events
where = myMap:getUserLocation ()
if where and where.errorCode == 0 then -- if we got a result this call
my_lat = where.latitude
my_long = where.longitude
timer.performWithDelay (10, remove_listener)
else
...(code to prevent indefinite looping not shown)
timer.performWithDelay (100, e_run_location)
end
...
function remove_listener ()
Runtime:removeEventListener ("location", e_run_location)
end
BTW, I noticed that when the handler (e_run_location) is called by the system (not in response to a getUserLocation), it has an event parameter with the GPS info in it
(i.e., I was perhaps misled into thinking I wouldn’t have to call getUserLocation.)
The demo example at https://docs.coronalabs.com/api/type/Map/getUserLocation.html
does not even mention the Runtime listener for “location”.
Per a report on forum from 2014, I won’t try to remove the listener from the listener.
thanks,
Stan