0

Das Problem, das ich habe, ist, ich versuche Google Maps api in meiner App arbeiten zu bekommen. hatte es funktioniert vorher, aber ich habe seit der Navigation Schublade zu meiner App hinzugefügt, die eine andere Art von Fragment verwendet android.app.Fragment und die Karte verwendet FragmentActivity, wenn ich den Code der Fragment-Klasse hinzufügen und android.app.Fragment erweitern, bekomme ich Folgendes errors.Wie man google maps api erhält, um von android.app.Fragment anstelle von Fragment Activity zu erweitern

Error:(46, 63) error: cannot find symbol method getSupportFragmentManager()

Error:(66, 48) error: incompatible types: MyMapFragment cannot be converted to Context

Error:(66, 171) error: incompatible types: MyMapFragment cannot be converted to Context

Hier ist meine Fragment-Klasse für die Karte

public class MyMapFragment extends android.app.Fragment implements OnMapReadyCallback { 

private GoogleMap mMap; 

public MyMapFragment() { 
    // Required empty public constructor 
} 


@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 

    View view = inflater.inflate(R.layout.fragment_map, container, false); 

    return view; 

    // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 
} 

Heres die fragment_map.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/map" 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="wit.ie.mightyangler.Fragment.MapFragment" /> 
+0

Wie ist das überhaupt compiling? Der Code unter Ihrer Rückkehr wird niemals gelesen – RafaelC

Antwort

0

Verwendung nicht-Version

MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); 
mapFragment.getMapAsync(this); 
unterstützen

und in xml

<fragment 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:name="com.google.android.gms.maps.MapFragment" 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/>