Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Geolocation works in Kitchensink, but not in my app

I've installed the KitchenSink on my Droid and its geolocation code works fine. Notably, the GPS icon appears in my notification bar the entire time that page is active.

I copy that code to my app, pretty much changing only variable names where the GPS data is saved. The GPS icon flashes briefly on the notification bar but does not stay. Sometimes my app will pull up the current location, sometimes a cached location from hour earlier. Most of the time, my app simply hangs and I have to force stop it.

Needless to say, this is quite frustrating. I've gone over the code in K-S and my code and there are no differences that should matter. The K-S code updates to labels on the screen. My code updates the values of text fields on a user entry form. But other than that, I haven't changed anything that should matter.

Currently I'm working with SDK version=1.4.2, timestamp=09/24/10 09:47, githash=949bc7 and the KitchenSink pulled from github that same day. But, this has been the same behavior with every SDK/nightly build back to the 1.4.0 release.

I've posted my version of the geo code at http://pastie.org/1184264

Any suggestions?

— asked September 27th 2010 by Tim Poulsen
  • android
  • geolocation
  • mobile
0 Comments

7 Answers

  • Have you monitored the log messages on device to see if you're getting any errors? You can use adb -d logcat or the ddms tool from the ADK/tools folder.

    — answered September 27th 2010 by Don Thorp
    permalink
    0 Comments
  • Have you monitored the log messages on device to see if you're getting any errors? You can use adb -d logcat or the ddms tool from the ADK/tools folder.

    — answered September 27th 2010 by Don Thorp
    permalink
    0 Comments
  • Thanks for the reply Don. I had not tried that. I think I understand what the log messages are saying and I can see location events firing. But, that might also be due to a change I made to my app (see below). I'll have to see if there's a way to save that log on the device and pull it later so that I can take my app on the road for testing.

    One difference between the Kitchen Sink and my app is that K-S constantly outputs the location data where mine saves it in variables which aren't read/output till the user taps a button which opens a view.

    So, I added a Lat/Long label to my UI and output the one-shot and current values to that label. In brief testing, this seems to keep my app from hanging. But the GPS icon still does not appear in the notification bar. I haven't traveled enough to see if it's actually being updated or not. It might not be because if I turn off my Droid's GPS, I don't get a warning message and initial lat/long values are output. So, maybe it's just pulling cached data.

    I'll take a long walk now and see if the app keeps up with the location changes.

    — answered September 27th 2010 by Tim Poulsen
    permalink
    0 Comments
  • As best as I can tell from logcat, the event listener is never firing. I had my Droid connected to my laptop with adb -d logcat running and I walked around. I see:

    D/libgps ( 1086): status_cb: GPS_STATUS_SESSION_BEGIN(1)
    ...
    I/TiAPI (31123): (kroll$3) [60,1755] geo - current location: ...
    D/libgps ( 1086): GpsInterface_stop()
    E/libgps ( 1086): recv_command_status() : fix returned error code 9
    ...
    D/libgps ( 1086): status_cb: GPS_STATUS_SESSION_END(2)
    

    And then that's the last GPS related info from my app. The geo - current location line is the Ti.API.info() call from my code. This is in the one-time GPS section.

    I see continual firings of the event listener when running the Kitchen Sink. For this test, I re-copied the Kitchen Sink code into my text. This time, the only change I made was to comment out lines updating UI labels I don't have.

    I've checked the AndroidManifest and tiapp.xml on both projects and they each contain the same resource type stuff. Obviously, my files has names, etc. related to my app that don't match those in the K-S files.

    — answered September 27th 2010 by Tim Poulsen
    permalink
    1 Comment
    • What I would suggest is to create a small test project with just the location listener part of it. Make sure that you set the location listener from within a heavyweight window so it get's the Android pause/resume messages to actually turn on the listener.

      — commented September 27th 2010 by Don Thorp
  • Don, your comment clued me in to the solution to the problem. You said "set the location listener from within a heavyweight window so it get's the Android pause/resume messages to actually turn on the listener". I realized that in my app, the geolocation code was in a window opened within the main app.js context. In the KitchenSink, it's loaded in a sub-context (via the hasChild facility of a table row).

    I made a new app to test this out. Geolocation code right in a window fails to fire the location event listener. Load it into a subcontext and it works.

    So, start a new project and you get the two-tabs/windows configuration. Put the geolocation code into a file called geo.js. Add the new tab as shown below and it works:

    var win3 = Titanium.UI.createWindow({
        url:'geo.js',
        title:'Geo'
    });
    var tab3 = Titanium.UI.createTab({
        icon:'KS_nav_ui.png',
        title:'Geo',
        window:win3
    });
    tabGroup.addTab(tab3);
    

    I've modified my app to load the window containing the geolocation code in this way and now it works! I still have some cleanup/restructuring to do with the rest of my app to support this new structure. But, it seems to be working as expected now.

    Thanks!
    Tim

    — answered September 29th 2010 by Tim Poulsen
    permalink
    0 Comments
  • by chance i've found this discussion. look a bit like my problem too. i'd be interested in why it works with the tabgroup approach and not in the window? i've made the same observation, with the code straight from the kitchen sink. works in a window opened from a tab, but not from (fullscreen)windows opened from within another window. any idea anybody?
    (sdk 1.5.1, android)
    –u

    — answered January 10th 2011 by u no
    permalink
    0 Comments
  • At this point, I don't recall the solution to the problem. My app is working (and published). The geo code is in a heavyweight window. I know at one point I was trying to put the geolocation stuff in a function and call it on demand. You can't do that because the geo services are asynchronous.

    On android, I call the geolocation stuff once, then set the event handler to fire every time the user moves 5 meters. On iphone, I did put the geo code in a function, which gets called every 15 seconds via setInterval. I had to tweak my code to handle the occasional null values in lat/long & address variables in case the async nature rears its ugly head.

    Sorry I'm not being more help. But I just don't remember what I was doing wrong at this stage of the game and what I did differently to get it working.

    — answered January 11th 2011 by Tim Poulsen
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.