创建地图的框架,其将在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我在尝试并感谢您的回答 –