クロスプラットフォームなコンテンツアプリ作成ツール

標題が長いな。
それはええとして appMobi の調査を云々という指令が海の向こうから飛んできたので、稼動空きを無理矢理作りつつ色々確認してみたんですが、なんとなく Titanium の方が上等なカンジです。
とりあえず map なサンプルを読んでみます。
ソースの出現順とは逆なんですが評価される順って事でご承知下さひ。最初は以下なナニが評価される模様です。

    //initial event handler to detect when appMobi is ready to roll
    document.addEventListener("appMobi.device.ready",onDeviceReady,false); 

appMobi.device.ready というイベントを掴まえて onDeviceReady という手続きを呼び出します。API reference によれば appMobi.device.ready は以下との事。

This event will fire once all AppMobi library information is loaded. Look for this event to fire before attempting any AppMobi commands.

ええと onDeviceReady 手続きが以下です。

    //AppMobi is ready to roll
    function onDeviceReady()
    {
        try
        {
            if (AppMobi.device.platform.indexOf("Android")!=-1)
            {
                AppMobi.display.useViewport(480,480);
                document.getElementById("map_canvas").style.width="480px";		
            }
            else if (AppMobi.device.platform.indexOf("iOS")!=-1)
            {
                if (AppMobi.device.model.indexOf("iPhone")!=-1 || AppMobi.device.model.indexOf("iPod")!=-1)
                {
                    AppMobi.display.useViewport(320,320);	
                    document.getElementById("map_canvas").style.width="320px";		
                }
                else if (AppMobi.device.model.indexOf("iPad")!=-1)
                {
                    AppMobi.display.useViewport(768,768);
                    document.getElementById("map_canvas").style.width="768px";		
                }
            }
        }
        catch(e)
        { 
            alert(e.message);
        }
        
        try
        {
            //lock orientation
            AppMobi.device.setRotateOrientation("portrait");
            AppMobi.device.setAutoRotate(false);
        }
        catch(e) {}
            
        try
        {
            //manage power
            AppMobi.device.managePower(true,false);
        }
        catch(e) {}
    
        //start computing location
        setTimeout("getLocation();",2000);
    }

やや冗長ですが

  • デバイス毎に viewport の調整をして
  • autoRotate を抑制
  • power management 云々 (スルー気味
  • 2 秒おきに getLocation 手続きを呼び出す

という処理をしている模様。2 秒おきに呼び出される getLocation ですが定義が以下。

    var getLocation = function()
    {
        dbAlert("in getLocation",4);

        if (AppMobi.geolocation != null)
        {
            AppMobi.geolocation.getCurrentPosition(suc,fail);
        }
    }

getCurrentPosition 手続きの呼び出しが成功した場合に限って確認します。suc の定義が以下。

	var suc = function(p){
		dbAlert("geolocation success",4);

		if( _map == null ) {
			currentLatitude = p.coords.latitude;
			currentLongitude = p.coords.longitude;
			drawMap();
		}
		else {
		  var image = 'beachflag.png';
		  var myLatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
		  var beachMarker = new google.maps.Marker({
		      position: myLatLng,
		      map: _map
  			});

  		  _llbounds.extend(new google.maps.LatLng(p.coords.latitude, p.coords.longitude));
  		  _map.fitBounds(_llbounds);
		}
	};
  • _map が null というのは最初の一発目という意味と見てます。
  • 引数 p が指してるオブジェクトは何かな。後で確認します。
  • maps API のバージョンは何だろ。
  • 引数でもらった座標を指す Marker 作って、LatLngBounds なソレで地図を書きなおしている模様。drawMap という手続きも初期処理という意味ではなかなかポイント高いんですが、このエントリでは略します。

課題

  • データの永続化な手法
    • ローカル、というよりは http なやりとりがどこまで出来るのか
    • javascript なのでなんとかはなるはずですが (ry