2016-11-12 2 views
0

я начать андроид студию с Google по умолчанию на карте: enter image description hereAndroid Google Map показать пустой экран

добавить свой ключ в google_maps_api.xml, и я уверен, что путь: enter image description here

это мой manifast:

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

    <!-- 
     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. 


    --> 


    <permission 
     android:name="com.example.erfan.google.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature"/> 
    <uses-permission android:name="com.example.erfan.google.permission.MAPS_RECEIVE"/> 

    <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.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 


    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     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> 

</manifest> 

Основная деятельность:

package com.example.erfan.google; 

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

где я ошибаюсь? попробовать так много предложений, в другой пост в стеке над потоком, но не работает для меня :(еще пустой карты Google: enter image description here

ответ

0

Прежде всего, убедитесь, что вы включили API Google Карт для Android в консоли разработчика и все интерфейсы, которые вы используете. Другой возможной причиной такого поведения является использование неправильного SHA 1, поэтому убедитесь, что вы правильно установили отпечаток SHA 1. Проверьте это documentation на то, как правильно получить ключ API и отпечаток SHA 1. Для получения дополнительной информации попробуйте следовать это tutorial о том, как использовать Google Maps для Android API

Take. Примечание: Вы должны назначить Debug API Key в тестировании, и Release Ключ API при выпуске APK. Просто вставьте правильный ключ API, очистите и перестройте свой проект, должно быть в порядке. Перед повторной загрузкой рекомендуется отключить старое приложение .

0

Случилось то же самое со мной. Я просто пошел здесь:

https://console.developers.google.com/apis/

И создал/активированный/включен еще один ключ, создав новый проект (левая панель -> Администрирование API).

Они дадут вам новый ключ.

Это сработало для меня.

Смежные вопросы