【问题标题】:Google Map v2 with Tabhost in Fragment Activity only show gray gridlines片段活动中带有 Tabhost 的 Google Map v2 仅显示灰色网格线
【发布时间】:2014-07-23 08:18:13
【问题描述】:
I am trying google map v2 in tabhost but google map unable to display properly that only showing gray grids, I have extended activity as fragment activity. I tried lots of solution to resolve this problem but nothing helps to me, other things are working properly, even if i open map in separate activity then i can able to do anything with the maps,Please help me to resolve this issue,Thanks in advance.
My code is:

 <RelativeLayout
            android:id="@+id/layMapFragment"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_weight="50" >

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

以下是我使用谷歌地图的方法,我不明白为什么地图不能在 tabhost 中工作,即使我已将相同的活动扩展为片段活动

public void declareView() {
        mMap = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();
        mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        mMap.setMyLocationEnabled(true);

        mMap.setOnMapClickListener(new OnMapClickListener() {

            @Override
            public void onMapClick(LatLng arg0) {


            }
        });

    }
}

【问题讨论】:

  • 发布快照...!!!
  • 大家好,我通过添加以下代码解决了我的问题: FragmentManager myFM = getSupportFragmentManager(); SupportMapFragment myMAPF = (SupportMapFragment) myFM .findFragmentById(R.id.map); myMAPF.onResume(); mMap = myMAPF.getMap(); mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); mMap.setMyLocationEnabled(true);

标签: android google-maps android-tabhost supportmapfragment


【解决方案1】:

很可能您还没有获取 Google Maps API 密钥。否则会阻止显示地图。有关如何获得一个访问此页面的说明:

https://developers.google.com/maps/documentation/android/#apikey

【讨论】:

  • 好的。您的 Logcat 中是否出现任何问题?
  • 不,Logcat 上没有任何内容
【解决方案2】:

您确定地图显示在普通片段中吗?

我的意思是您是否尝试先在没有 tabhost 的情况下显示地图?确保地图工作正常?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 2013-07-18
    相关资源
    最近更新 更多