views:

50

answers:

1

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?

A: 

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

anticafe
Thank you for the response. I think its working now, the issue though is google map loads but its blank. Is this because I have to have some special certificate for using the google map service on the android?
John
Are you using this map on Android? In Appcelerator Titanium: "For Android, you will need to obtain a map key from Google to use maps in your application." So, at first you need to get a map key of Google from http://goo.gl/K5yz. After having a map key, open your PROJECT_DIR/tiapp.xml, add 2 property ti.android.google.map.api.key.development and ti.android.google.map.api.key.production as in KitchenSink tiapp.xml (http://goo.gl/PFdk). Remember to change "GET_ME_FROM_GOOGLE" to your map API key. Good luck.
anticafe