【问题标题】:Can I change a SupportMapFragment to a Mapview on Google Maps v2?我可以在 Google Maps v2 上将 SupportMapFragment 更改为 Mapview 吗?
【发布时间】:2013-06-28 00:18:54
【问题描述】:

Google 是否允许在 v2 上使用 MapView 与 MapFragments 或 SupportMapFragments?我有一个使用 SupportMapFragment 的 layer.xml 文件,如何在使用下面使用的 LinearLayout 和 RelativeLayouts 时将其更改为 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);
}

【问题讨论】:

    标签: android android-mapview google-maps-android-api-2 supportmapfragment


    【解决方案1】:

    Google 是否允许在 v2 上使用 MapView 与 MapFragments 或 SupportMapFragments?

    是的。

    如何在使用下面使用的 LinearLayout 和 RelativeLayouts 时将其更改为 MapView?

    AFAIK,它应该是:

    第 1 步:将您的 &lt;fragment&gt; 替换为:

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

    第 2 步:关注 the instructions on the MapView class documentation 将生命周期事件转发到视图

    【讨论】:

    • 所以这个应用程序已经发布了,这对 API 密钥有什么改变吗?我之前使用 SHA1 生成密钥?
    • @MarkBasler:这应该不会影响您的 API 密钥。
    • 现在我的扩展 mapactivity 的 Activity 会改变代码吗?
    • 例如 lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mf= (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);地图 = mf.getMap();
    • @cassioso: MapFragment 用于片段的原生 API 级别 11 实现。 SupportMapFragment 用于 Android 支持包的片段反向移植。
    猜你喜欢
    • 2012-11-23
    • 2015-02-19
    • 2013-01-09
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多