Android Application crashes badly on adding mapview.

You must Login before you can answer or comment on any questions.

I am trying to create a mapview in tabbar window but my application crashes badly whenever I try to add mapview. I even try to add to add a view and add my mapview onto it and add that view onto window but application is still crashes sometime randomly. My focus is being called twice I am enclosing my code as below aswell. Looking for urgent suggestions.

var mapview = Titanium.Map.createView({
    top:0,
    height: 391,
    mapType: Titanium.Map.STANDARD_TYPE,
    region:{latitude:latStr, longitude:lonStr, latitudeDelta:0.2, longitudeDelta:0.2},
    animate:true,
    regionFit:true,
    userLocation:false,
    //annotations:[atlanta1,appleAnn],
});
 
 
if (latStr || lonStr) {
 
    mapview.region = {latitude:latStr, longitude:lonStr, latitudeDelta:0.2, longitudeDelta:0.2};    
}
 
if (!appleAnn) {
    mapview.annotations = [atlanta1];
} else {
    if (atlanta1) {
        mapview.annotations = [atlanta1,appleAnn];
    }
}
//win4.add(mapview);    //  Applications crashes whenever I visit map tab
So I add mapview in focus as
var mapHolder = Ti.UI.createView({
    size:{height:391, width:'auto'},
    top:86,
    left:0,
    //backgroundImage:'../images/bkg-header.png',
    backgroundColor:'#000',
    modal:true,
    //borderColor:'blue',
    zIndex:0
});
win4.add(mapHolder);
 
 
var mapCheck = false;
var focusCheck = false;
 
win4.addEventListener('focus', function(e) {
 
 if (focusCheck == false) {
 
        if (mapview)
        {
            var children = mapHolder.children.slice(0);
 
            for (var i = 0; i < children.length; ++i) {
                mapHolder.remove(children[i]);
            }
        }
 
        //alert('focus Check');
        mapCheck = true;
        focusCheck = true;
 
        mapHolder.add(mapview);
 
        /*if (mapview) {
            win4.remove(mapview);
        }
        win4.add(mapview);*/
 
     }
})
But my code for adding mapview didnt workout and event Listener 'open' is also not being callled. I m bit frustrated that why mapview is creating crahes on Android, although all annotations work is also being done.

— asked 8 months ago by Umaid Saleem
3 Comments
  • you shouldnt be trying to remove the mapview.... it will crash

    — commented 8 months ago by Aaron Saunders

  • Hi Aaron, Why is it like so? even i would like to know the reason of it.

    — commented 8 months ago by Ashish Nigam

  • It is still crashing , I guess it is a memory leak as my focus is being called twice and open didnt called and when I try to add mapview outside

    var win4 = Titanium.UI.currentWindow;
     
    var mapview = Titanium.Map.createView({
        top:0,
        height: 391,
        mapType: Titanium.Map.STANDARD_TYPE,
        region:{latitude:latStr, longitude:lonStr, latitudeDelta:0.2, longitudeDelta:0.2},
        animate:true,
        regionFit:true,
        userLocation:false,
        //annotations:[atlanta1,appleAnn],
    });
    win4.add(mapview);
    This is crashing aswell , as it was working fine before , I am enclosing my window onto tabbar code below aswell

    var win41 = Ti.UI.createWindow({
                width: 'auto',
                height: 'auto',
                top: 0,
                left: 0,
                backgroundImage: 'images/bkg-complete.png',
                url: 'ui/mapview_update.js',
                //title: 'Favourites',
                barImage: 'images/bkg-header.png',
                //exitOnClose:true,
                backgroundColor:'#000'
            });
     
    var tab4 = Ti.UI.createTab({
                   icon:'images/map_icon.png',
                   //title:'Map',
                   window: win41,
                   //backgroundFocusedImage: 'images/bkg-complete.png',
                    borderColor:'#000',
                    backbackgroundColor:'#000'
             });
     
    tabGroup.addTab(tab4);
     
    tabGroup.open();

    — commented 8 months ago by Umaid Saleem

Your Answer

Think you can help? Login to answer this question!