Ich versuche, eine sehr einfache MapView auf einer meiner Aktivitäten anzuzeigen, jedoch ist meine MapView für immer leer nie Laden einer Karte. Said MapView ist nur eine 200px Höhe einer Aktivität, die andere Elemente hat. Ich habe keine Map-Aktivität vom Assistenten erstellt.Android Google Maps grundlegende Karte
Mein Manifest hat:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!--
The API key for Google Maps-based APIs.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="my real code" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Mein build.gradle hat die Abhängigkeit:
compile 'com.google.android.gms:play-services-maps:10.2.1'
Meine Android Studio hat die Googleplay-Paket. Würdest du wissen, was ich vermisse?
Dies ist der XML-Code für mein mapView:
<LinearLayout
android:id="@+id/geolocationLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Geolocation"
android:textStyle="bold|italic" />
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="200dp" />
</LinearLayout>
Diese meine Tätigkeit Java-Klasse ist Karte Deklaration und Verladung:
Erklärungen:
MapView mapView;
GoogleMap map;
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
Innen OnCreateView:
mapView = (MapView) view.findViewById(R.id.mapView);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
}
});
Wo ist die mapView.onCreate (...)? – Blackkara
Ich habe mapView.onCreate (mBundle) hinzugefügt; und jetzt sehe ich die mapView mit Google-Logo auf der linken unteren Seite, aber die Karte ist nicht geladen ... Muss ich etwas anderes Code? – user1060551
Wenn die Zuordnung leer ist, ist das häufig auftretende Problem ein ungültiger API-Schlüssel –