2016-04-06 11 views
1

私のプロジェクトでは、マップをプログラム上でフラグメントにロードしています。ただし、この地図上にマーカーを追加しても機能しません。エラーは表示されませんが、マーカーはマップにも表示されません。マーカーが表示されない:Google Map Android

私はspecificationに従っています。なぜそれが機能しないのかわかりません。 (緯度とLNGマーカーのカメラが同じである)

マイ・フラグメントコード

public class MainMapFragment extends Fragment implements OnMapReadyCallback { 
SupportMapFragment mMapFragment; 
static final LatLng LIBRARY = new LatLng(Lat, Lng); 
@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    return inflater.inflate(R.layout.main_map_layout,container,false); 
} 

@Override 
public void onViewCreated(View view, Bundle savedInstanceState) { 
    //Set the initial stage of the map 
    //It is set on code (not on the xml) because the map is created programmatically 
    GoogleMapOptions options = new GoogleMapOptions(); 
    CameraPosition ufv_position = new CameraPosition.Builder() 
      .target(new LatLng(Lat,Lng)) 
      .zoom(15) 
      .tilt(0) 
      .bearing(40) 
      .build(); 

    options.mapType(GoogleMap.MAP_TYPE_NORMAL) 
      .compassEnabled(false) 
      .rotateGesturesEnabled(false) 
      .tiltGesturesEnabled(false) 
      .camera(ufv_position); 
    //Load the map with the given options 
    mMapFragment = SupportMapFragment.newInstance(options); 
    FragmentTransaction fragmentTransaction = 
      getChildFragmentManager().beginTransaction(); 
    fragmentTransaction.add(R.id.map, mMapFragment); 
    fragmentTransaction.commit(); 
} 

@Override 
public void onMapReady(GoogleMap googleMap) { 

    googleMap.addMarker(new MarkerOptions() 
      .position(LIBRARY) 
      .title("Library") 
      .icon(BitmapDescriptorFactory.fromResource(R.drawable.book))); 


} 

}

+0

呼び出さmMapFragment.getMapAsync(this);を追加質問の座標。しかし私は同じ場所にカメラを設置しました。 (これは有効な座標です) –

答えて

0

ので、あなたのonMapReady方法は、私はちょうど隠さ

関連する問題