Titanium Map Annotations crash the application

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

I've narrowed everything down to this - if I add Annotations (which work perfectly fine on iOS Simulator and Device) to map, then the Application instantly crashes on Launch.

This is my code and Log:

// Check if the Platform is Android, if so, I need to determine which images to use
// This is so due to the bug that existed up to Titanium version 2.0 and I haven't checked if it's still there (the correct image isn't automatically picked out from the corresponding folder, like Resources/android/res-long-land-hdpi/, etc.)
 
if (Ti.Platform.osname === "android") {
    dpi = Titanium.Platform.displayCaps.dpi;
    if (dpi < 160) {
      prefix = 'l';
    } else if (dpi >= 160 && dpi < 240) {
      prefix = 'm';
    } else if (dpi >= 240 && dpi < 320) {
      prefix = 'h';
    } else if (dpi >= 320) {
      prefix = 'x';
    } else {
      prefix = 'm';
    }
    pinButton = "/images/" + prefix + "RightArrow.png";
    pinImage = "/images/" + prefix + "Pin.png";
  } else { 
     // On iPhone things are much more simple, and everything just works.
    pinButton = Titanium.UI.iPhone.SystemButton.DISCLOSURE;
    pinImage = null;
  }
 
  // mapData is an Array that is pulled from SQLite with information like latitude, longitute, address, text, etc.
  // So I'm creating an Annotation for each pin, and pushing them all into an array
  allPins = (function() {
    var _i, _len, _results;
    _results = [];
    for (_i = 0, _len = mapData.length; _i < _len; _i++) {
      pin = mapData[_i];
      _results.push(Ti.Map.createAnnotation({
        entryid: pin.id,
        latitude: pin.la,
        longitude: pin.lo,
        title: pin.text,
        subtitle: pin.address,
        pincolor: Titanium.Map.ANNOTATION_GREEN,
        animate: false,
        rightButton: pinButton,
        image: pinImage
      }));
    }
    return _results;
  })();
 
 // Finally I create a Map View,
  mapView = Ti.Map.createView({
    mapType: Titanium.Map.STANDARD_TYPE,
    region: that.region,
    animate: true,
    regionFit: true,
    userLocation: true
  });
Now if after "userLocation" (or anywhere else in crateView for that matter) I add the Array of Annotation objects, like this:
mapView = Ti.Map.createView({
     mapType: Titanium.Map.STANDARD_TYPE,
     region: that.region,
      animate: true,
      regionFit: true,
      userLocation: true,
      annotations: allPins
    });
then I get an App "Force Quit" crash and this is what is in the log: http://pastebin.com/VnUxL1rX

Please Help.

— asked 9 months ago by Nauris Pukis
5 Comments
  • Also, when I limit the SQLite Query LIMIT 0, 10 it works. Only trouble is that I need to display the 160 pins! 10 don't suit me at all.

    — commented 9 months ago by Nauris Pukis

  • I made a memory test on iOS, and with all the pins, it doesn't consume more than 4MB of ram with fall the activity I could do in the app.

    — commented 9 months ago by Nauris Pukis

  • Try this declare an array var allPins= []; then a annotation var anni = Ti.Map.createAnnotation({}) outside of the loop. then in the loop add to the annotation data to the anni. when you loop is done do the following allPins=anni; Keep your mapview as is. Also be sure you not addund the annotation before they get created. Do the loop before you add them ot the map.

    — commented 9 months ago by Chris Berry

  • Show 2 more comments

1 Answer

This way you can determine if the break is in the creation of the annotation data or the adding of the annotation. Do you have an idea of how many annotation you care trying to create? Also consider using a try catch to track down the problem.

try {
//your loop
} catch(e) {
   alert(e.message);
}

— answered 9 months ago by Chris Berry
answer permalink
2 Comments
  • I'm trying to create around 130 Annotations. In a different application I use the same code-base, but even more Annotations (about 180) and there is no crash.

    — commented 9 months ago by Nauris Pukis

  • Did you get anywhere with this?

    — commented 9 months ago by Chris Berry

Your Answer

Think you can help? Login to answer this question!