2013-10-12 58 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();