谷歌地图不显示标记。这是我用于添加标记的代码片段
googleMap = ((MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
return ;
}
try {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
} catch (Exception e) {
Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_LONG).show();
}
这是我的 xml 布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
似乎一切都很好,地图及其在实际屏幕上的显示。请注意,我在未从 MapFragment 扩展的片段(支持库)中使用此片段。有任何想法吗?