【发布时间】:2014-10-31 12:13:39
【问题描述】:
我能够使用以下 Activity 布局成功地初始化 GoogleMap API 2.0:
<RelativeLayout
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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/fragment_container">
<fragment
android:id="@+id/ganbi_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</FrameLayout>
</RelativeLayout>
现在我正在尝试引用此片段以使用以下代码设置几个选项:
private GoogleMap gMap;
.
.
.
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (gMap == null) {
gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.ganbi_map)).getMap();
// Check if we were successful in obtaining the map.
if (gMap != null) {
// The Map is verified. It is now safe to manipulate the map.
// Load map preferences
Log.d("Info","Map ready for initailization");
}
}
}
这会导致致命错误,并且跟踪归咎于以下行:gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.ganbi_map)).getMap();
有什么建议吗?
【问题讨论】:
标签: android google-maps android-fragments google-maps-android-api-2