創建地圖的框架,其將在XML佈局中添加
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map_container">
<!-- The map fragments will go here -->
</RelativeLayout>
不包括無論是在你的片段類XML類=「com.google.android.gms.maps.SupportMapFragment」嗎手動獲取它onActivityCreated
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FragmentManager fm = getChildFragmentManager();
fragment = (SupportMapFragment) fm.findFragmentById(R.id.map_container);
if (fragment == null) {
fragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map_container, fragment).commit();
}
/***at this time google play services is not initialized so get map and add what ever you want to it in onResume() or onStart() **/
}
@Override
public void onResume() {
super.onResume();
if (map == null) {
map = fragment.getMap();
map.addMarker(new MarkerOptions().position(new LatLng(0, 0)));
}
}
請參閱https://developers.google.com/maps/documentation/android/ –
是的,這是非常可能的。除了@DixitPatel鏈接的文檔中提供的內容之外,沒有太多要添加。只需按照那裏的步驟。 – Rarw
@DixitPatel我在嘗試並感謝您的回答 –