John
John

Reputation: 15

Cannot add to current window in titanium appcelerator. Get type error

I just started learning titanium for mobile using the android. I followed all the install steps and got the hello world script to work just find in the android emulator. The problem is Im trying to use example code to see how it all works. The example code Im currently having problems with is:

    var win = Titanium.UI.currentWindow;

var mapview = Titanium.Map.createView({
    mapType: Titanium.Map.STANDARD_TYPE,
    region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
    animate:true,
    regionFit:true,
    userLocation:true
});
win.add(mapview);

When I run this in the emulator I get the following error:

TypeError: Cannot call method "add" of null.

What am I doing wrong?

Upvotes: 0

Views: 3025

Answers (1)

anticafe
anticafe

Reputation: 6892

I think in Ti.Map.createView(), you miss the annotations parameter. The full code of create a MapView must like this:

var win = Titanium.UI.currentWindow;
var anno1 = Titanium.Map.createAnnotation({
    latitude:33.74, longitude:84.38,
    title:'POI 1',
    pincolor:Ti.Map.ANNOTATION_RED
});
var anno2 = Titanium.Map.createAnnotation({
    latitude:33.75, longitude:84.39,
    title:'POI 2',
    pincolor:Ti.Map.ANNOTATION_RED
});
var mapview = Titanium.Map.createView({
    mapType: Titanium.Map.STANDARD_TYPE,
    region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
    animate:true,
    regionFit:true,
    userLocation:true,
    annotations:[anno1, anno2]
});
win.add(mapview);

Let try this and let me know if it work :)

Upvotes: 2

Related Questions