Problem
When I attempt to access annotations on a map view created by Ti.Map in Alloy I find that the annotations are undefined, however they are displayed on the map. I do not have this issue when creating the map using the traditional method.
I need to be able to get all the current annotations and loop through them, I have tried using the getAnnotations() method but no results are returned.
This issue does not exist with the map on iOS.
Below is the code to reproduce this issue.
alloy.js
Alloy.Globals.Map = require('ti.map');
index.xml
<Alloy>
<Window>
<!-- Use the Alloy.Globals.Map namespace to create a map module view -->
<View id="mapview" ns="Alloy.Globals.Map" onClick="report" />
</Window>
</Alloy>
index.js
function report(evt) {
Ti.API.info("Annotation " + evt.title + " clicked, id: " + evt.annotation.myid);
}
// API calls to the map module need to use the Alloy.Globals.Map reference
var mountainView = Alloy.Globals.Map.createAnnotation({
latitude:37.390749,
longitude:-122.081651,
title:"Appcelerator Headquarters",
subtitle:'Mountain View, CA',
pincolor:Alloy.Globals.Map.ANNOTATION_RED,
myid:1 // Custom property to uniquely identify this annotation.
});
$.mapview.region = {latitude:33.74511, longitude:-84.38993,
latitudeDelta:0.01, longitudeDelta:0.01};
$.mapview.addAnnotations([mountainView]);
alert($.mapview.getAnnotations().length);
Alloy app
Surprisingly I couldn't use the Alloy global namespace (got a module not found error). Then reproduced the getAnnotations() issue on TiSDK 3.1.1.GA using controller shown below:iOS reports "1" meanwhile Android returns "0".
Titanium app
On TiSDK 3.1.1.GA on iOS Simulator v6.1.2 returns "1" annotations, meanwhile Android just returns "0" annotations. If same method is tested by a Titanium simple sample length property is undefined.Device stack trace (Razr 2.3.5)
Simple sample
I did find a method to get the annotations on Android. However you have to create the annotations prior to creating the view, and any annotations added after creating the view are not returned by getAnnotations(). This doesn't solve my issue since I am creating and deleting annotations on the fly.
master PR: https://github.com/appcelerator-modules/ti.map/pull/3
Testing steps: 1. Run the classic titanium test case mentioned in the above comment. Should see an alert showing '4'. 2. Run app.js from example/app.js inside the map module. Play around with 'Annotation Test' suite and make sure there are no regressions. 3. Run this additional test case
You should see an alert printing '2', and logcat should have the content of those 2 annotations. 4. Change line 61 in the above code to 100 (instead of 1000), also try to run the block without setTimeout. The result should be the same.
Verified with test environment: Appcelerator Studio: 3.2.0.201311122338 SDK:3.2.0.v20131113183932 alloy: 1.3.0 acs: 1.0.7 npm: 1.3.2 titanium: 3.2.0 titanium-code-processor: 1.1.0 Xcode:5.0.2 Device: Google Nexus7(v4.3) OS: Mac OSX 10.9 getAnnotation() working fine.