Ich versuche einfach, mein Map-Fragment zu bekommen, um dann getmapasync auszuführen und Marker darauf zu zeichnen. Mein mapFragment-Wert ist jedoch immer null. Ich verstehe nicht warum. Ich lese aus anderen Antworten, dass es etwas mit der Tatsache zu tun hat, dass mein Fragment in einem Rahmen ist und daher eine Art Kind ist.getSupportFragmentManager(). FindFragmentById gibt null auf GoogleMap zurück
Hier ist mein Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
startService(new Intent(MainActivity.this, TrackerService.class));
bindService(new Intent(MainActivity.this, TrackerService.class), myConnection, Context.BIND_AUTO_CREATE);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
Log.d("DEBUG", "MAP READY");
mMap = googleMap;
drawLocationMarkers();
}
Und die XML:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="@drawable/custom_card"
android:layout_weight="0.5">
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/map"
class="com.google.android.gms.maps.MapFragment"/>
</FrameLayout>
Haben u umgesetzt zu verwenden Ihre Aktivitätsklasse mit OnMapReadyCallback – Nainal
Bitte beziehen Sie sich auf den Link https://developers.google.com/maps/documentation/android-api/ – Nainal
@Nainal ja ich habe, ich habe meine Frage aktualisiert, bitte sehen Sie –