Google Maps [API] 视图在我的移动设备上呈灰色 [英] Google Maps [API] view is gray on my mobile device

查看:39
本文介绍了Google Maps [API] 视图在我的移动设备上呈灰色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我真的需要你的帮助.

Hi guyes I really need your help.

我已阅读此链接上有关如何使用 Google API 的说明:https://developers.google.com/maps/documentation/android/start

I've read the instructions on how to use Google API on this link: https://developers.google.com/maps/documentation/android/start

我已完成所有七个步骤,但无法在我的应用中显示 Google 地图.

I've followed all seven steps but I couldn't display Google Map in my app.

[我已经厌倦了让模拟器工作,所以我决定生成一个 APK 文件并将其发送到我的智能手机]安装应用程序后,一旦我打开它,我只能在屏幕左侧看到灰色屏幕和Google"签名.就是这样,什么都没有发生.

[I have already got tired from trying to get the Emulator to work so I've decided to generate an APK file instead and send it to my smartphone] After intalling the app, once I open it I can only see a grey screen and 'Google' signeture at the bottem left of the screen. that's all, nothing happens.

当我连接我的设备并使用调试模式时,该应用程序运行良好.我试过通过 adb 安装它,但它仍然没有工作.

The app works fine when I connect my device and use the debug mode. I've tried installing it Via the adb but it still didn't work.

过去三天我一直在关注关于这个问题的许多文章,但无论我尝试过什么,它都没有奏效.

I've been following many articles for the last three days regarding this issue but no matter what I've tried it just didn't work.

我做错了什么?

这是我的代码:

清单:

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

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

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

    <application


        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <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>
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIza**********"/>
    </application>

</manifest>

主要活动 Java:

package josh.com.googlemap2;

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 {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap map) {
        // Add a marker in Sydney, Australia, and move the camera.
        LatLng sydney = new LatLng(-34, 151);
        map.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        map.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }

}

主要活动布局:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/map"
    tools:context=".MapsActivity"
    android:name="com.google.android.gms.maps.SupportMapFragment" />

Goole_Maps_api.xml

Goole_Maps_api.xml

 <string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
        AIzaSyAnvkHr4CGYzmROT*******
    </string>
</resources>

推荐答案

好的,如果你遇到类似的情况,有两点需要注意:

Alright, There are two things that you should note if you encounter a similar situation:

1) 有两个 google maps api.xml 文件,一个用于发布,一个用于调试.您可以在这些路径上找到它们:

1) There are two google maps api.xml files, one for release and one for debug. you can find them on these paths:

\app\src\release\res\values

\app\src\release\res\values

\app\src\debug\res\values

\app\src\debug\res\values

确保在两个文件中都添加您的 Google Map Key!

Make sure to add your Google Map Key on both files!

2) 我没有在官方来源上找到此信息,但除了常规的 SHA1 密钥之外,您还需要为发布文件生成另一个 SHA1 密钥.

2) I didn't find this information on official source but you need to generate another SHA1 key for the release file in addition to your regular SHA1 key.

您必须有两个 SHA1 密钥,一个用于调试版本,一个用于发布版本.

You must have two SHA1 keys, one for the debug version and one for the release version.

获得发布文件的新密钥后,将其添加到 Google API 控制台第二行的现有密钥中.

Once you have the new key for the release file, add it to your Google API Console exisiting key at the second row.

这篇关于Google Maps [API] 视图在我的移动设备上呈灰色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆