1

谷歌地图不显示标记。这是我用于添加标记的代码片段

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 扩展的片段(支持库)中使用此片段。有任何想法吗?

4

2 回答 2

0

更改您的 LatLng 并将地图上的缩放设置到该位置,看看是否显示在那里......例如:

map.moveCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(44.797283, 20.460663), 12))

map.addMarker(new MarkerOptions()
.position(new LatLng(44.797283, 20.460663))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

有关详细信息:如何在 GoogeMapAPIv2 上添加标记

于 2014-02-01T14:54:11.427 回答
0

替换此行

googleMap = ((MapFragment)getActivity().getFragmentManager().findFragmentById(R.id.map))
.getMap();

这样

googleMap = ((SupportMapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
于 2015-02-23T21:13:50.427 回答