Ich versuche, eine Google Maps in einer sehr einfachen Anwendung anzuzeigen (ein neues Projekt mit nur einer Google Maps Aktivität) das Manifest enthält die Berechtigungen:Google Maps leeren Bildschirm zeigt
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ivan.pruebamaps">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Ich habe einen gültigen Geben Sie @ string/google_maps_key ein.
Die mainActivity ist unberührt, genauso wie es in Android Studio erstellt wurde.
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// 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);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
Das gleiche geschieht mit der Layout-Datei activity_maps:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
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="com.example.ivan.pruebamaps.MapsActivity" />
Dies ist meine gradle Datei, wenn das hilft:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.ivan.pruebamaps"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.google.android.gms:play-services-maps:10.2.0'
testCompile 'junit:junit:4.12'
}
Wenn ich die app ausführen bekomme ich nur einen Bildschirm mit ein leerer Bildschirm und das Google-Logo in der linken unteren Ecke. Ich versuche es in einem emulierten Nexus 5, und in einer Samsung Galaxy s6 funktioniert das auch nicht.
Das Problem "leere Karte" ist immer auf einen schlechten API-Schlüssel zurückzuführen. Überprüfen Sie die Protokolle, dort sollte ein Fehler sein. –
In der Tat bekomme ich eine Nachricht in dem Protokoll, die mir sagt, dass ich überprüfen soll, ob mein Schlüssel existiert. Was ist unglaublich, weil ich das gleiche Projekt in einem anderen PC mit SDK 24 versuchte und es funktionierte. Ich bin erstaunt. – Asdemuertes