2013-10-12 212 views
1

谷歌地图不显示标记。 下面是用于添加标记谷歌地图API不显示标记

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> 

好像一切都很好地图及其在实际屏幕显示。请注意,我在片段(支持lib)内使用此片段,而不是从MapFragment扩展。 任何想法?

回答

0

在地图上的经纬度的设置和缩放变化到那个地方,看看是否是显示有... 例如:

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))); 

欲了解更多信息:How to add a marker on GoogeMapAPIv2

0

替换该行

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

通过这个

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