Question

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?

Was it helpful?

Solution

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 :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top