2016-04-12 7 views
0

Ich bin kein Programmierer, aber mache eine sehr einfache Android-Entwicklung App durch Arbeit.Google Maps zeigt leere Seite in Android App

Ich habe es geschafft, alle Config Keys einzurichten, um einen Google Map-Bildschirm in meiner App zum Laufen zu bringen. Wenn ich jedoch klicke, um den Kartenbildschirm zu öffnen, wird eine leere Karte angezeigt (nur ein Google-Logo unten auf meinem Bildschirm).

Ich habe Fragen von Menschen hier mit ähnlichen Thema angeschaut, also vermute ich, dass ich bestimmte Berechtigungen in meinem Android-Manifest hinzufügen und auch ein bisschen mit meinem Java-Code spielen? So würde wirklich gehofft, jemand in der Lage sein, meinen Code zu schauen und zeigen Sie mir in die richtige Richtung (eine Art Baby-Schritte ...)

Dank

Android Manifest xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.android.learn5things"> 

    <!-- 
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
     Google Maps Android API v2, but you must specify either coarse or fine 
     location permissions for the 'MyLocation' functionality. 
    --> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".LocationActivity" /> 
     <activity android:name=".CultureActivity" /> 
     <activity android:name=".FoodActivity" /> 
     <activity android:name=".FootballActivity" /> 
     <activity android:name=".CarnavalActivity" /> 

     <!-- 
      The API key for Google Maps-based APIs is defined as a string resource. 
      (See the file "res/values/google_maps_api.xml"). 
      Note that the API key is linked to the encryption key used to sign the APK. 
      You need a different API key for each encryption key, including the release key that is used to 
      sign the APK for publishing. 
      You can define the keys for the debug and release targets in src/debug/ and src/release/. 
     --> 
     <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"></activity> 
    </application> 

</manifest> 

Aktivität Karten (XML)

<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.android.learn5things.MapsActivity" /> 

M aps-Aktivität (Java-Datei)

package com.example.android.learn5things; 

import android.support.v4.app.FragmentActivity; 
import android.os.Bundle; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

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); 
    } 


    /** 
    * Manipulates the map once available. 
    * This callback is triggered when the map is ready to be used. 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
    * we just add a marker near Sydney, Australia. 
    * If Google Play services is not installed on the device, the user will be prompted to install 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
    * installed Google Play services and returned to the app. 
    */ 
    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     // Add a marker in Brazil and move the camera 
     LatLng brazil = new LatLng(-8.892710, -56.098682); 
     mMap.addMarker(new MarkerOptions().position(brazil).title("Marker in Brazil")); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(brazil)); 

    } 
} 
+0

Haben Sie eine erhaltene Schlüssel in 'google_maps_key' Wert? Überprüfen Sie res/values ​​/ google_maps_api.xml – Blackkara

Antwort

0

Sie müssen klären Google Services Version in Ihrer manifest.xml Datei unter Anwendung Tag Spiele:

<meta-data 
    android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" /> 

Auch ich denke, dass Ihr Google Maps-API-Schlüssel sein sollte verwiesen als:

<meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="@string/google_maps_key" /> 

Also, stellen Sie sicher, dass Sie Ihre aktuelle Google maps Key in die Saiten setzen Datei! Ich hoffe, es hat geholfen.

Source

+0

Vielen Dank Arunce für Ihre Hilfe! Ich habe im Fehlerprotokoll festgestellt, dass ein Problem mit meinem API-Schlüssel aufgetreten ist. Also ging ich in Google Entwickler und generierte einen neuen und das scheint das Problem gelöst zu haben. Ich habe noch nicht versucht, Ihre Vorschläge zu implementieren, da sie jetzt wie erwartet zu funktionieren scheinen, aber ich könnte gehen und sie später aktualisieren und sehen, ob sich noch etwas ändert? Danke nochmal für deine Hilfe! –

+0

Ja, das ist mir auch mal passiert, kein Problem :) –