最終更新:
moonlight_aska 2014年02月02日(日) 23:28:40履歴
「Googleマップを表示する」を参照し, Googleマップが表示できるようにする.
or
class="com.google.android.gms.maps.SupportMapFragment"

- res/layout/activity_main.xml
- 地図表示のためのフラグメントを配置する.
- android:layout_weight属性に, オブジェクトの占有比率を指定する.
- Android 3.0 (API 12 HonyComb) 以上を対象とする場合は MapFragment, サポートパッケージを利用する場合は SupportMapFragment を指定する.
or
class="com.google.android.gms.maps.SupportMapFragment"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
class="com.google.android.gms.maps.SupportMapFragment"
/>
<fragment
android:id="@+id/map2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
class="com.google.android.gms.maps.SupportMapFragment"
/>
</LinearLayout>
- MainActivity.java
- android.support.v4.app.FragmentActivityをインポートする.
- FragmentActivityを継承したActivityクラスを作成する.
package com.moonlight_aska.android.web.googlemap001;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
private GoogleMap mMap1 = null;
private GoogleMap mMap2 = null;
private static final LatLng OSAKA_STATION = new LatLng(34.702177, 135.495114);
private static final LatLng TOKYO_STATION = new LatLng(35.681382, 139.766084);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMap1 = ( (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map1) ).getMap();
if (mMap1 != null) {
CameraPosition cameraPos = new CameraPosition.Builder()
.target(OSAKA_STATION)
.zoom(10.0f)
.bearing(0).build();
mMap1.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos));
}
mMap2 = ( (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map2) ).getMap();
if (mMap2 != null) {
CameraPosition cameraPos = new CameraPosition.Builder()
.target(TOKYO_STATION)
.zoom(10.0f)
.bearing(0).build();
mMap2.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos));
}
}
}
- 動作例

コメントをかく