Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

GPS issue with Android (location event triggered only once, no further updates)
Started by heftyApps Jul 21 2014 12:30 AM

19 replies to this topic

Best Answer heftyApps , 25 July 2014 - 10:24 PM

Just downloaded CoronaSDK 2014.2381 and it has been fixed. Thank you!

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

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

Hello,

 

I have an issue with the event listener "location" on my Android devices (Galaxy Note (N7000, first model) and Galaxy Note 8.0). What I need to do is get the users distance to a previously saved location, e.g. you save your position via GPS data (latitude/longitude), move on and then want to know how far away you are away from that initially saved location.

 

My build.settings is complete and provides for all the relevant settings (including android.permission.ACCESS_FINE_LOCATION and android.permission.ACCESS_COURSE_LOCATION). I also added the relevant event listener: 

 

Runtime:addEventListener( "location", locationHandler )

 

Basically, whenever the app is running and the user is moving, the event listener should be triggered at some point in time and I should be able to retrieve updated latitude/longitude information via the locationHandler function. However, the event listener seems to get only triggered once at startup with no further updates/events triggered thereafter.

 

My app runs perfectly fine on iOS (iPhone 5) and continously delivers GPS data (latitude/longitude) and I cannot see why it fails on Android. All GPS settings on my Android device are enabled, everyhing relevant is switched on but still no further location events are triggered. I am using build CoronaSDK 2014.2373.

 

To be sure that this had nothing to do with my app, I compiled another one which just waits for and reads the latitude/longitude values via the location listener, outputs them to the screen and vibrates the phone. All fine on iOS with constant data being delivered / event being triggered but no luck with my Android devices. The event listener is fired upon start of the app but no further updates thereafter.

 

I installed some apps from Google's Store which display GPS data (latitude, longitude, satellite fix, etc.) and these are all doing fine, so my Android devices are working properly, however not with my Corona compiled apps.

 

Did anyone else encounter the same issue and could help me out? I have been trying to solve this for days now but I am stuck. My app is actually done but I cannot publish for Android with this issue being in place. I have no clue how to fix this.

 

Thanks.

Jens



[TOPIC: post.html]
#2

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi Jens,

Can you please post your code regarding how you've set up the listener?

 

Also, I apologize that the docs had a misspelling on one of the Android permissions. It should be ACCESS_COARSE_LOCATION, not ACCESS_COURSE_LOCATION. This will be corrected shortly (although that still may not solve your issue).

 

Thanks,

Brent



[TOPIC: post.html]
#3

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

Hi Brent,

 

this is what I use at the very end of my main.lua file:

 

 ---------------------------------------------------------------------------------------------------------------------------------------
 -- Add GPS related event listeners
 ---------------------------------------------------------------------------------------------------------------------------------------
 Runtime:addEventListener( "location", GPSSignalStrength )
 Runtime:addEventListener( "location", GPSlocationHandler )
 Runtime:addEventListener( "heading",  GPSheadingHandler )
 ---------------------------------------------------------------------------------------------------------------------------------------
-- require storyboard
local storyboard = require "storyboard"
-- load first scene
storyboard.gotoScene("mainscreen")

 

 

The functions  GPSSignalStrength(), GPSlocationHandler() and GPSheadingHandler() are sitting in a separate lua.file which I am requiring prior to adding the event listeners.

 

My GPSlocationHandler() function then tries to evaluate the longitude and latitude data:

 

function GPSlocationHandler (event)
   -- Check for error (user may have turned off Location Services)
    if event.errorCode then
        -- display error message
        --print("GPS Location Error: ".. tostring( event.errorMessage ))
       
        -- reset GPS signal counter
        appData.totalSignals    = 0
        appData.GPSacquired     = false
    else
        appData.totalSignals = appData.totalSignals + 1
        if appData.totalSignals < 2 then appData.GPSacquired = false return end
        -- retrieve latitude / longitude information
        _G.currentLatitude  = tonumber(string.format( '%.4f', event.latitude ))
        _G.currentLongitude = tonumber(string.format( '%.4f', event.longitude ))
...
...
...

 

Is the issue that I am initialising two "location" event listeners whereas Corona / the device can only handle one of these at a time  (either GPSSignalStrength or GPSlocationHandler) but not both?

 

Jens



[TOPIC: post.html]
#4

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi Jens,

I'm not sure if two listeners is the cause or not, but it could be. Can you remove one and see if the results vary?

 

Also, there may be some weirdness going on because the functions aren't in the same Lua file. Would it be easy for you to quickly try putting one locally in the same module and seeing if you get constant signals?

 

Best regards,

Brent



[TOPIC: post.html]
#5

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

Hi Brent,

 

I did all of the above (renamed to ACCESS_COURSE_LOCATION, only added one event listener for "location" and put my code into one module) but no change. The location event listener is only triggered once upon start of the app or if app has been put to the background and is resumed. I tried my code on further devices, including Samsung Galaxy S3 and HTC M8 (One) - no difference, the listener is not called subsequently.

 

I compiled the GPS sample code which comes with Corona and it suffers from the same issue. I therefore think that this is a bug with Corona when compiled for Android. iOS is doing just fine. Would you be able to run Corona's GPS sample code on an Android device and see for yourself if this is a bug? Should you have any other idea how to fix this, please let me know. Unfortunately, this issue is holding me up in getting my app published for Android.

 

Maybe someone else on this forum could test Corona's own GPS example on Android as well and let me know if the same issue is experienced.

 

Update: Now filed a bug report, Case 34330. Still, any update/help would be appreciated.

 

Thanks,

Jens



[TOPIC: post.html]
#6

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

Some notes:

- The actual setting is "ACCESS_COARSE_LOCATION", you said "COURSE" just above

- Many devices do not get GPS updates inside buildings, you should see a blinky map pin like icon in your android title bar (slide down top of screen to view it while app is running).  The map pin icon in the android title bar blinks while it is attempting to get GPS, and goes solid once the gps has got a coordinate. Watching this icon while your app works can be helpful (no real GPS coords are passed in to the app until it stops blinking in the title bar).

- Watch the android console as well, it generates a furious amount of messages / updates once the droid GPS is warmed up



[TOPIC: post.html]
#7

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

Hi, as noted above

 

- I changed the code to read ACCESS_COARSE_LOCATION with no effect

- I included only one location listener with no effect

- I moved all location event relevant routines to one and the same file with no effect

 

All my testing has been done outdoors with perfect GPS signals / fixes. To verify that the phones actually received good GPS signals I installed various GPS apps and they all worked perfectly fine and behaved like expected. However, my own compiled app as well as Coronalabs's own GPS app failed to provide any further location updates and this all on three different devices. For me, this is definitely and issue / bug which is with Corlonalabs' compiler, not the devices I tested. Hopefully, someone from Coronalabs can report back soon on this.



[TOPIC: post.html]
#8

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

I'm running android 4.4.2 and get a gps icon (looks like a map pin) in the devices status bar. Is the icon in the status bar when your app is running / in the foreground? If so, is it blinking or solid?



[TOPIC: post.html]
#9

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

Hi, it is solid and I am running 4.4.2 on a HTC One (M8). I now had the event.latitude and event.longitude echoed to device's screen (via native.showAlert) and walked around a bit. The event listener is triggered for  3-5 times at the beginning of the app being started, then it suddenly stops with no further updates. Whenever I restart the app or resume it from the background, the same happens over again (3-5 events fired, then dead silence).

 

It would be great if you could compile Corona's GPS example and test it on your device. Does it behave like expected, e.g. is it constantly providing location updates when you walk around or only in the beginning and then it stops, too?

 

Jens



[TOPIC: post.html]
#10

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

It sounds like the GPS is definitely on and warmed up (not blinking). In my case, yes, I am receiving tons of location events - very noisy on my droid (Samsung S3, android 4.4.2).

 

Corona has a couple of sdk gps settings - I set them manually, don't know what system defaults are though:

 

system.setLocationAccuracy( 10 )        -- Set accuracy of gps to 10 meters (conserve battery. iOS options are
system.setLocationThreshold( 5 )        -- Set location notification threshold to 5 meter distance change... (battery conservation)        
 

Also, you might want to put a print / sound effect in the code for event.errorCode section of your location handler, just in case something odd is happening (it resets your counter to skip reading each error, but if there were a series or interleaved errors, you wouldn't get coords either).

 

Also, due to some other gps related issues, I changed the structure of my location handler even further than you have... I'm now using the "table method", described in this post:

 

http://forums.coronalabs.com/topic/46572-get-latitudelongitude-and-stop-location-runtime-event/page-2#entry257104

 

In my case, it allows me to turn on / off the location / other events during system events (suspend/resume).  I've run into some other map / gps issues, and that workaround seemed to help get me *almost* to where I need to be.



[TOPIC: post.html]
#11

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

mpappas, I tried to register the loaction handler via the table method and to Change accuracy and threshold but it did not change anything for me. Neither did I receive any event.errorCode messages. One thing that may different from your coding is that you seem to remove your event listener upon having received data once, I however need to have GPS data updated constantly and this is why I cannot remove the listener. Maybe this is why you have not noticed any issues as described by me.

 

Have you tried Corona's GPS sample code on your device and does it constantly update location data as you move around? You would do me a great favour if you could test this since I have not heard back from Coronalabs staff yet. I am somewhat stranded and have no idea how to fix this or if I am the only experiencing these issues.

 

Coronalabs, please help -  I am out of ideas  :unsure: Is this a bug?



[TOPIC: post.html]
#12

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

I'm actually just using the table method so I can turn the gps on/off at certain times (from inside another event handler). But in general, it's always on in my app, and works 100% (too much it seems, very noisy / lot of events generated).

 

It sounds like you've ruled out a lot of things at this point.  I will have some time later today to give the gps sample app a try (SampleCode/Hardware/GPS folder right?).  I've got a Samsung S3 and Nexus 7 I'll run it on and see what I get.



[TOPIC: post.html]
#13

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

Yes, that is the correct folder. Thank you for helping out on this.



[TOPIC: post.html]
#14

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

I am getting the same thing with the GPS sample app, just 1-2 initial updates to GPS coords, and then nothing unless suspend/resume. I turned off wifi, power saving, changed the sample to a table listener... and still just the initial GPS update.

So I can verify for you, the sample app doesn't update gps coordinates on a samsung S3 running 4.4.2 (Corona build 2373).



[TOPIC: post.html]
#15

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

Mpappas, thank you for testing.

@Coronalabs, could you please fix this?

[TOPIC: post.html]
#16

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

Submitted as bug #34382.



[TOPIC: post.html]
#17

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

@Coronalabs: Out of curiosity, I installed the latest public release (Build 2014.2189) and the event listener works as expected, also on Android. So something must have happened with the introductions of one of the last daily builds which caused the listener to become buggy. Please fix.



[TOPIC: post.html]
#18

mpappas

[GLOBAL: userInfoPane.html]
mpappas
  • Contributor

  • 527 posts
  • Enterprise

Already got an email reply on the bug I submitted -- that was pretty fast!

 

Hi,

This issue has been fixed and will be in build 2381.

--
Corona Labs - Support
support@coronalabs.com



[TOPIC: post.html]
#19

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

Great news!

[TOPIC: post.html]
#20

heftyApps

[GLOBAL: userInfoPane.html]
heftyApps
  • Contributor

  • 102 posts
  • Corona SDK

  Best Answer

Just downloaded CoronaSDK 2014.2381 and it has been fixed. Thank you!




[topic_controls]
[/topic_controls]