Titanium Community Questions & Answer Archive

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

What's the maximum number of annotations?

I have a list with 3000 POI's. But the app crashes once I add the array to the mapview

Is there a maximum number of annotations which are allowed to add to the mapview? Or do I need an entirely different approach?

I also want to warn the user, once he approaches one of these POI's. Is that possible?

// Get current window
var win = Titanium.UI.currentWindow;

// Annotations array
var locations = [];

// Read locations from file
Ti.API.info('loading locations...');
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'data.txt');
var contents = f.read();
var rows = contents.text.split('\n');
for (var i = 0; i < rows.length; i++) {
    var cols = rows[i].split(',');

    var latitude = cols[3];
    var longitude = cols[2];
    var title = cols[5].replace(/\"/g, "");
    var subtitle = cols[1].replace(/\"/g, "");

    locations[i] = Titanium.Map.createAnnotation({
        latitude: latitude,
        longitude: longitude,
        title: title,
        subtitle: subtitle,        
        pincolor:Titanium.Map.ANNOTATION_RED,
        animate:true,
        myid: (i + 1)
    });
}

Ti.API.info('done!');

var mapview = Titanium.Map.createView({
    mapType: Titanium.Map.STANDARD_TYPE,
    region: {latitude:51.97919, longitude:5.90493, latitudeDelta:0.8, longitudeDelta:0.8},
    animate:true,
    regionFit:true,
    userLocation:true,
    annotations:locations
});

win.add(mapview);
— asked July 11th 2010 by Maurice Krijtenberg
  • android
  • annotations
  • google
  • maps
  • mapview
  • mobile
1 Comment
  • Maurice,
    have you found the maximum number of annotations ?
    I have the same problem with about 2500 annotations.
    Regards

    — commented February 23rd 2012 by Armindo Da Silva

1 Answer

  • Accepted Answer

    That's a heafty number of annotations to add at one time.

    I'd suggest testing to see how many it can comfortably handle - divide by 2, test, then rinse & repeat until you find it stable.

    It might be wise to implement some smarter logic around selecting which annotations to display using the lat/long & the current latDelta/longDelta to create a bounding box. From this you should be able to generate a lat/long for each of the 4 corners of the screen - which you can use to select which annotations to display.

    If you convert your text file to a sqlite db - then you can use the calc'd corner bounds in your select.

    — answered July 11th 2010 by David Ashwood
    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.