1

Google は、v2 で MapFragments または SupportMapFragments に対して MapView を使用することを許可していますか? 以下で使用している LinearLayout と RelativeLayouts を利用しながら、SupportMapFragment を使用している layer.xml ファイルを MapView に変更するにはどうすればよいですか?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <Button
        android:id="@+id/btn_draw"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text=" Get Directions"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn_find"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/str_btn_find"
            android:layout_alignParentRight="true" />

        <EditText
            android:id="@+id/et_location"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="@string/hnt_et_location"
            android:layout_toLeftOf="@id/btn_find" />

    </RelativeLayout>



    <fragment 
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>

私のコードもどのように変更されますか?

/**
 * Shows the users current location on the map
 */
private void showCurrentLocationOnMap(){
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mf= (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

    map = mf.getMap();

    //map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    ll = new PointLocationListener();

    boolean isGPS = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);

    if (!isGPS){
        Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
        intent.putExtra("enabled", true);
        sendBroadcast(intent);
    }

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 10, ll);
}
4

1 に答える 1

3

Google は、v2 で MapFragments または SupportMapFragments に対して MapView を使用することを許可していますか?

はい。

以下で使用している LinearLayout と RelativeLayouts を利用しているときに、それを MapView に変更するにはどうすればよいですか?

私の知る限り、それは単に次のようになるはずです:

ステップ#1:あなた<fragment>を次のものに置き換えます:

<com.google.android.gms.maps.MapView 
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>

ステップ #2:クラスのドキュメントの指示MapViewに従って、ライフサイクル イベントをビューに転送します。

于 2013-06-28T00:21:40.697 に答える