1> 在 Fragment 增加高德地图的 com.amap.api.maps.SupportMapFragment
直接通过在XML布局文件中添加
<fragment
android:id ="@+id/roadcondition_map_f"
android:layout_width ="match_parent"
android:layout_height ="match_parent"
class= "com.amap.api.maps.SupportMapFragment" />
调用 getSupportFragmentManager() 返回为空,因此使用代码直接添加
<1> 在xml增加要显示地图的布局
<FrameLayout
android:id ="@+id/navigation_map_fl"
android:layout_width ="match_parent"
android:layout_height ="match_parent"
android:layout_marginBottom ="60dp" />
<2> 代码使用SupportMapFragment填充布局
if (mAMap == null)
{
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
try
{
MapsInitializer. initialize( activity);
}
catch (RemoteException e)
{
e.printStackTrace();
}
SupportMapFragment supportMapFragment = new SupportMapFragment();
transaction.replace(R.id. navigation_map_fl , supportMapFragment);
transaction.commit();
mAMap = supportMapFragment.getMap();
}