2016-04-06 21 views
1

In meinem Projekt lade ich meine Karten programmatisch auf ein Fragment. Das Hinzufügen von Markierungen auf dieser Karte funktioniert jedoch nicht. Es wird kein Fehler angezeigt, aber der Marker ist nicht auf der Karte.Marker wird nicht angezeigt: Google Map Android

Ich folge dem specification so habe ich keine Ahnung, warum es nicht funktioniert. (Lat und Lng der Markierung und der Kamera sind die gleichen)

Mein Fragment-Code

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

ich nur versteckt aufgerufen wird die Koordinaten der Frage. Aber ich stelle es auf den gleichen Platz, den ich meine Kamera einstelle. (Es ist eine gültige Koordinate) –

Antwort

0

hinzufügen mMapFragment.getMapAsync(this); so Ihre onMapReady Methode