2017-09-20 1 views
0

Je suis créé un nouveau projet android avec une activité google map. mon code d'activité est:Google map montrant des carreaux gris seulement sur android studio

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

}

et ceci est mon manifeste:

<?xml version="1.0" encoding="utf-8"?> 

<!-- 
    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.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
<uses-permission android:name="xxxxxx.permission.MAPS_RECEIVE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.CALL_PHONE" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="com.google.android.providers.gsf.permisson.READ_GSERVICES"/> 

<uses-permission android:name="xxxxx.mapservice.permission.MAPS_RECIEVE"/> 
<uses-permission android:name="xxxxx.provides.gsf.permission.READ_GSERVICES"/> 
<permission android:name="xxxxx.mapservice.permission.MAPS_RECIEVE" 
    android:protectionLevel="signature"/> 

<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"> 

    <!-- 
     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"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

et je me suis un google api clé et limiter avec la touche sh1. J'ai suivi la documentation de google mais malheureusement ma carte ne se charge pas.

Alors que je suis à la recherche de quelques commentaires suggérant que je devrais supprimer le debug.keystore mais cela ne fonctionne pas pour moi. Qu'est-ce que je rate?

également ma mise en page carte fichier xml est:

<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="ir.iuwa.testmap.MapsActivity" /> 

Répondre

0

Ajouter ceci dans votre extérieur manifeste de la balise d'application et vérifiez

<uses-feature 
android:glEsVersion="0x00020000" 
android:required="true" /> 
0

J'ai trouvé la solution! Mon tort était de générer le code sha1 correct. Auparavant, j'ai trouvé cette clé en utilisant le menu gradle à côté droit de studio android en utilisant la procédure suivante: d'abord en cliquant sur gradle puis, sous l'application, tâches, android, je clique sur signingReport:

enter image description here

alors le SHA1 est apparu dans la console gradle:

enter image description here

Mon falut était que ce code est pour le mode de débogage! J'ai suivi la procédure ci-dessous pour obtenir la version sha1 pour mon keystore de sortie et après avoir entré ce nouveau sha1 dans google developer console ma carte apparaît complètement. Pour obtenir la version sha1, vous devez d'abord copier l'adresse de votre magasin de clés: allez dans build >> generateSigendApk et copiez le chemin de votre magasin de clés.

enter image description here

alors vous devez copier le chemin de votre jdk ce studio Android utilise. Allez dans Fichier >> ProjectStructure et vous pouvez voir votre chemin jdk. copier ce chemin et dans cmd aller dans ce dossier.

enter image description here

Puis cd yor jdk puis le dossier bin et copiez la ligne suivante: keytool -list -v -keystore "VOTRE MAGASIN COPIES KEY PATH" de "KEY ALIAS" Entrez maintenant et profitez de votre libérer le code sha1 :)