我想SupportMapFragment
在Fragment
容器中加载一个。我没有收到任何错误,我的 API 密钥很好,Google Play 服务库已导入并调用了所有权限。
我这样称呼MapFragment
:
MapaFragment fragment = new MapaFragment();
FragmentTransaction ft2 = getFragmentManager().beginTransaction();
ft2.replace(android.R.id.tabcontent, fragment)
.commit();
Fragment
如下:
public class MapaFragment extends SupportMapFragment {
private View v;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
v=inflater.inflate(R.layout.mapa, null);
return v;
}
地图的布局就这么简单:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapa"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>