【问题标题】:Android Google Map show blank screenAndroid 谷歌地图显示黑屏
【发布时间】:2017-03-26 11:37:01
【问题描述】:

我使用默认的谷歌地图启动 android studio:

在 google_maps_api.xml 中添加我的密钥,我确定路径:

这是我的清单:

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

我哪里错了?在堆栈溢出的另一篇文章中尝试这么多建议,但对我不起作用:(仍然是空白的谷歌地图:

【问题讨论】:

    标签: java google-maps android-studio


    【解决方案1】:

    你必须去https://console.developers.google.com/apis/credentials,在你选择API Key之后点击编辑(铅笔图标)然后去页面下方 单击添加“包名和 SHA-1 证书指纹” 然后添加此信息并保存

    注意:设置最多可能需要 5 分钟才能生效

    【讨论】:

      【解决方案2】:

      首先,确保您在开发者控制台中启用了 Google Maps Android API 以及您正在使用的所有 API。此行为的另一个可能原因是使用了不正确的 SHA 1,因此请确保正确获取 SHA 1 指纹。查看此documentation,了解如何正确获取 API 密钥和 SHA 1 指纹。如需更多信息,请尝试关注tutorial,了解如何使用 Google Maps Android API。

      注意:您必须在测试中分配调试 API 密钥,然后发布 发布 APK 时的 API Key。只需插入正确的 API 密钥,清理并 重建你的项目应该没问题。建议卸载你的 重新加载之前设备中的旧应用程序。

      【讨论】:

        【解决方案3】:

        我也遇到了同样的情况。我刚到这里:

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

        并通过创建新项目(左窗格 -> API 管理)创建/激活/启用另一个密钥。

        他们会给你一把新钥匙。

        它对我有用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-04-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-05-16
          • 1970-01-01
          相关资源
          最近更新 更多