Titanium Community Questions & Answer Archive

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

Maps - tapping Back closes the app

I'm having problems with maps. If I create a map view and open it in the current window, when a user taps the Android back button, my app closes. If I put the map in its own window, the app hangs and that window never opens.

Perhaps it's the convoluted nature of my app?

app.js - a switcher file that sets some common variables and then loads the appropriate screen.

mainwindow.js - the window that contains the button users tap to view the map

I have the exitOnClose property set to true on the mainwindow to match the expected behavior of the app. (Other windows could be opened by app.js and when you click back on them, I don't want the app to close.) If I set this to false, and remove the event handler that watches for the android back button, tapping the back button in the map takes me back to the splash screen. From there, I can't do anything but kill the app.

I've tried setting an event listener w/in the map view to do something custom when the back button is pressed while the map is open. With that in place, I get dumped back to the splash screen.

I'm running Titanium 1.2.1 (so says the title bar). I've tried with the 1.3.2, 1.4.0, and up through last night's nightly build of 1.4.1. Developing on Windows for Android using the 1.6 APIs.

— asked September 10th 2010 by Tim Poulsen
  • android
  • map
0 Comments

1 Answer

  • I've solved my own problem. I'm now showing the map within its own window. The reason that was hanging was apparently caused by the way I was adding annotations to the map. I think it exposed a bug in Titanium.

    var stuff = db.get_db_info(userid);
    var myAnnotations = new Array();
    for(s in stuff) {
        var dbMarker = Titanium.Map.createAnnotation({
            animate:true,
            pincolor:Titanium.Map.ANNOTATION_PURPLE,
            latitude:stuff[s]['latitude'],
            longitude:stuff[s]['longitude'],
            title:stuff[s]['title'],
            address:stuff[s]['longitude'][s]['address'],
            myid:stuff[s]['longitude'][s]['id']
        });
        myAnnotations.push(dbMarker);
    } // end for/in
    

    Then, later I added the markers in another loop but, when showing the map in its own new window, it hung at the first iteration. It worked fine in a view in the mainwindow, but then I had the back button issues.

    for (i=0;i<myAnnotations.length;i++){
        mapview.addAnnotation(myAnnotations[i]); //put pin on map
    }
    

    Instead, this works

    mapview.annotations = myAnnotations;
    

    With this change, the new window opens the map. Tapping the back button takes me back to my mainwindow.

    Tim

    — answered September 10th 2010 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.