2012年6月6日水曜日

MAP表示


地図表示サンプル

    private MapView         mapView;//Mapビュー
    private MapController   mapCtrl;//Mapコントローラ
    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.setting);              

       //Mapビューの生成
        mapView=(MapView) findViewById(R.id.Map); //(this,API_KEY);
        mapView.setBuiltInZoomControls(true);
      
        mapCtrl=mapView.getController();

        //中心の緯度、経度を指定
        mapCtrl.setCenter(new GeoPoint(
                (int)(36.24831*1E6),
                (int)(139.533294*1E6))); 
    
        mapCtrl.setZoom(16); 

}

Layout xml (API Keyをあらかじめ取得しておく)

        <com.google.android.maps.MapView
          android:id="@+id/Map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:enabled="true"
          android:clickable="true"    
          android:apiKey="05fjECm****************ZgcHR6SzVdUmQ"
            />

Manifestへ追加

<application>の中へ
        <uses-library android:name="com.google.android.maps"/>  

target はGoogle APIにする。



Google MAP API Keyの取得方法はこちらを参照

http://www.android-group.jp/index.php?%CA%D9%B6%AF%B2%F1%2FMapsAPIKey

0 件のコメント:

コメントを投稿