0
votes

I'm trying to add annotations to my map in Titanium and I keep ending up with this error:

"line = 37;

message = "Invalid type passed to function";

Invalid type passed to function"

nativeLocation = "-[TiMapViewProxy annotationFromArg:] (TiMapViewProxy.m:120)";

nativeReason = "expected: Object, was: NSNull";"

Here's my code. As far as I know it should work.

//This is the code to implement a map and store locations using annotations
var locationsTabGroup = Titanium.UI.createTabGroup({
    barColor: '#E62B2B'
});


var locationsToHome = Titanium.UI.createButton({
title: 'Back',
titleAttributes: {
color: 'white'
},
backgroundImage: 'images/revisedbackbutton2.png',
height: 35,
width: 80,
borderRadius: 10
});

var locationsWindow = Titanium.UI.createWindow({  
    leftNavButton: locationsToHome,
    title:'Select Store',
    tabBarHidden: true,
    titleAttributes:  {
        color:'white'
       }
});

var MapModule = require('ti.map');

var locationsMap = MapModule.createView({
    mapType: MapModule.NORMAL_TYPE,
    animate: true,
    region: {latitude: -27.962939, longitude: 153.382428, latitudeDelta: 0.1, longitudeDelta: 0.1 },
    height: '100%',
    top: 0,
    width: Ti.UI.FILL,
    annotations: [store1]
});

var store1 = MapModule.createAnnotation({
    latitude: -27.465868,
    longitude: 153.028309,
    pincolor: MapModule.ANNOTATION_RED,   
    title: 'Pita Pit Brisbane',
    subtitle: '280 Adelaide St, Brisbane QLD 4000'
});

var store2 = MapModule.createAnnotation({
    latitude: -27.499154,
    longitude: 152.972711,
    pincolor: MapModule.ANNOTATION_RED,   
   title: 'Pita Pit Indooroopilly',
    subtitle: '322 Moggill Rd, Indooroopilly QLD 4068'
});

var store3 = MapModule.createAnnotation({
    latitude: -27.453312,
    longitude: 153.034908,
    pincolor: MapModule.ANNOTATION_RED,   
    title: 'Pita Pit Green Square',
    subtitle: '6/515 St Pauls Terrace, Fortitude Valley QLD 4006'
});

var locationsTab = Titanium.UI.createTab({  
    window: locationsWindow
});

locationsWindow.add(locationsMap);
locationsTabGroup.addTab(locationsTab);  
1

1 Answers

0
votes

You are using the annotation before it is created. You should declare all your annotations before passing them to the map.

Or don't set the annotations at creation and use locationsMap.setAnnotations([store1, store2, store3]); once your annotations have been declared.