not good but great

プログラミング、アート、映画・本の感想について書きます。

Ti.Map.createViewがundefinedのときは、ti.mapモジュールを追加する

地図を表示する

var map = Ti.Map.createView({
	mapType:Ti.Map.STANDARD_TYPE,
	region:{latitude:35.456,longitude:139.71,latitudeDelta:0.01,longitudeDelta:0.01},
	animate:true,
	regionFit:true,
	width:300,
	height:400
});

ドットインストールを参考にして書いてみました。
#16 地図を表示させてみよう (1) | 【サポート終了】Titanium Mobile入門 - プログラミングならドットインストール

エラーが出た

message = "'undefined' is not an object (evaluating 'Ti.Map.createView')";

調べると以下のページが出てきました。バージョンによって書き方が違うみたいです。
Axway Software · GitHub

Titanium 3.2.0以降では使えない

DEPRECATED

3.2.0

For new Android applications or to use Google Maps v2, use the ti.map add-on module.

For the iOS platform, use the ti.map add-on module. Support for the Titanium.Map module on iOS was removed in Release 3.2.0.

For all other platforms, continue to use this module.

どうやらTi.Mapは廃止されたようで、使いたいときは「ti.map」というモジュールを追加すれば良いみたいです。
Appcelerator Documentation

「ti.map」モジュールを追加する

f:id:naoyashiga:20140223230827j:plain
timap.xmlのモジュール追加画面より、ti.mapモジュールを選択して追加すれば良いです。

コード

//モジュール追加
var Map = require("ti.map");

var win = Ti.UI.createWindow({
	backgroundColor:"#EBE2D9"
});

var view = Ti.UI.createView();

var map = Map.createView({
	mapType:Map.STANDARD_TYPE,
	region:{latitude:35.645,longitude:139.71,latitudeDelta:0.01,longitudeDelta:0.01},
	animate:true,
	regionFit:true,
	userLocation:true,//ユーザの現在地を使用する
	width:300,
	height:400
});
view.add(map);
win.add(view);
win.open();

ドットインストールでは「userLocation:true」は出てきませんでした。これをtrueにすると「現在地を使用したい」というアラートを表示しないようになります。

結果

f:id:naoyashiga:20140223231624j:plain
恵比寿周辺の地図を見ることが出来ました。