谷歌地图显示空白屏幕左下方有“谷歌”标志

时间:2017-05-02 14:14:27

标签: java android xml google-maps-api-3

我已经搜索并搜索过,并为不同的人找到了这个问题的许多不同的解决方案,但我所尝试的一切在我的情况下都没有成功。

基本上我添加了Google地图并复制了我的SHA-1指纹(双重和三重检查它是正确的)并将我的API密钥粘贴到Android Manifest中(再次双重和三重检查密钥是否正确)。

在谷歌开发控制台中,图表显示我加载地图的峰值,但从来没有能够看到除空白屏幕以外的任何内容。

我安装了Google Repository,Google Play服务等。

我还在清单中添加了权限,并在build.gradle中添加了依赖项。

我还创建了一个新的Google Maps Activity,以便在/ src /中自动生成/ debug和/ release文件夹以及.xml文件,并使用当前和重新生成的API密钥更新它们。我已经复制了自动生成的链接,以生成没有运气的API密钥。

因为问题似乎是地图不会加载告诉我指纹或API密钥一定有问题,但我不知道还有什么可以尝试。

我现在正在模拟器上运行并且在具有相同问题的实际设备中尝试过一次。

我仍然是Android Studio和Java的新手,因此很可能是答案就像一个痛苦的拇指一样突出!

Blank Map

的AndroidManifest.xml

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

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MAPS_RECEIVE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <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">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- Map API Key -->


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

fragment_contact.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.gms.maps.MapView
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="200dp" />


</FrameLayout>

ContactFragment.java

package assignment2.thebookmark;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

/**
 * Created by brandanmcdevitt on 26/04/2017.
 */

public class ContactFragment extends Fragment implements OnMapReadyCallback {

    GoogleMap mGoogleMap;
    MapView mMapView;
    View mView;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_contact, container, false);

        return mView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        mMapView = (MapView) mView.findViewById(R.id.map);
        if (mMapView != null) {
            mMapView.onCreate(null);
            mMapView.onResume();
            mMapView.getMapAsync(this);
        }

    }

    @Override
    public void onMapReady(GoogleMap googleMap) {

        MapsInitializer.initialize(getContext());
        mGoogleMap = googleMap;
        googleMap.setMapType(GoogleMap.MAP_TYPE_NONE);

        LatLng headOffice = new LatLng(54.508460, -6.763554);

        googleMap.addMarker(new MarkerOptions().position(headOffice).title("The Reading Room").snippet("The Beginning of Your Next Adventure"));

        googleMap.moveCamera(CameraUpdateFactory.newLatLng(headOffice));

    }
}

编辑,logcat

05-02 18:57:10.587 3507-3507/assignment2.thebookmark I/zzai: Making Creator dynamically
05-02 18:57:10.591 3507-3507/assignment2.thebookmark W/System: ClassLoader referenced unknown path: /system/priv-app/PrebuiltGmsCore/lib/x86
05-02 18:57:10.591 3507-3507/assignment2.thebookmark D/ApplicationLoaders: ignored Vulkan layer search path /system/priv-app/PrebuiltGmsCore/lib/x86:/system/fake-libs:/system/priv-app/PrebuiltGmsCore/PrebuiltGmsCore.apk!/lib/x86:/system/lib:/vendor/lib for namespace 0xb507d090
05-02 18:57:10.607 3507-3507/assignment2.thebookmark W/System: ClassLoader referenced unknown path: 
05-02 18:57:10.607 3507-3507/assignment2.thebookmark W/System: ClassLoader referenced unknown path: /system/priv-app/PrebuiltGmsCore/lib/x86
05-02 18:57:10.608 3507-3507/assignment2.thebookmark D/ApplicationLoaders: ignored Vulkan layer search path /system/priv-app/PrebuiltGmsCore/lib/x86:/system/fake-libs:/system/priv-app/PrebuiltGmsCore/PrebuiltGmsCore.apk!/lib/x86:/system/lib:/vendor/lib for namespace 0xb507d0d0
05-02 18:57:10.615 3507-3507/assignment2.thebookmark W/System: ClassLoader referenced unknown path: 

/data/user_de/0/com.google.android.gms/app_chimera/m/00000002/n/x86
05-02 18:57:10.645 3507-3507/assignment2.thebookmark I/Google Maps Android API: Google Play services client version: 10240000
05-02 18:57:10.662 3507-3507/assignment2.thebookmark I/Google Maps Android API: Google Play services package version: 10298470
05-02 18:57:10.822 3507-3673/assignment2.thebookmark D/NetworkSecurityConfig: No Network Security Config specified, using platform default

                                                                              [ 05-02 18:57:10.939  3507: 3698 D/         ]
                                                                              HostConnection::get() New Host Connection established 0xabf1df40, tid 3698
05-02 18:57:10.984 3507-3507/assignment2.thebookmark 

W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
05-02 18:57:12.913 3507-3700/assignment2.thebookmark W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
05-02 18:57:12.928 3507-3700/assignment2.thebookmark I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:2
05-02 18:57:12.928 3507-3700/assignment2.thebookmark I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 2

1 个答案:

答案 0 :(得分:1)

从我所看到的,你错过了最重要的许可:

<uses-permission android:name="android.permission.INTERNET" />

没有它,您的应用就无法访问互联网,因此无法下载地图并显示白屏(如您所述)

由于这对你不起作用,请尝试添加:

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