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);
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.