谷歌地图[API]的观点是灰色的我的移动设备上 [英] Google Maps [API] view is gray on my mobile device

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

问题描述

喜guyes我真的需要你的帮助。

我读过关于如何使用谷歌API这个环节上的说明:
https://developers.google.com/maps/documentation/android/start

我已经照着所有的七个步骤,但在我的应用我无法显示谷歌地图。

[我已经厌倦了在试图让模拟器来工作,所以我决定生成APK文件,而不是并将其发送到智能手机]
intalling应用程序后,有一次我打开它,我只能看到一个灰色的屏幕和'谷歌'signeture在屏幕左侧的bottem。这一切,什么都不会发生。

当连接我的设备,并使用调试模式的应用程序工作正常。
我试着安装它通过亚洲开发银行,但它仍然没有奏效。

我一直在关注的最后三天就这个问题,但不管是什么我已经试过了只是没有工作的文章。

我在做什么错了?

下面是我的code:

清单:

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=josh.com.googlemapslast>    <使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
    <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
    <使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>    <用途特征
        机器人:glEsVersion =0x00020000
        机器人:要求=真/>    <应用
        机器人:allowBackup =真
        机器人:图标=@的mipmap / ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        &所述;元数据
            机器人:名字=com.google.android.gms.version
            机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>        <活动
            机器人:名字=。MapsActivity
            机器人:标签=@字符串/ title_activity_maps>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        &所述;元数据
            机器人:名字=com.google.android.geo.API_KEY
            机器人:值=AIza **********/>
    < /用途>< /清单>

主要活动的Java:

 包josh.com.googlemap2;进口android.support.v4.app.FragmentActivity;
进口android.os.Bundle;进口com.google.android.gms.maps.CameraUpdateFactory;
进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.OnMa preadyCallback;
进口com.google.android.gms.maps.SupportMapFragment;
进口com.google.android.gms.maps.model.LatLng;
进口com.google.android.gms.maps.model.MarkerOptions;
公共类MapsActivity扩展FragmentActivity实现OnMa $ P $ {padyCallback    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_maps);
        SupportMapFragment mapFragment =(SupportMapFragment)getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(本);
    }    @覆盖
    公共无效onMa pready(GoogleMap的地图){
        //在澳大利亚悉尼添加标记,然后移动相机。
        经纬度悉尼=新的经纬度(-34,151);
        map.addMarker(新的MarkerOptions()位置(悉尼).title伪(标记在悉尼));
        map.moveCamera(CameraUpdateFactory.newLatLng(悉尼));
    }}

主要活动布局:

 <片段的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:ID =@ + ID /图
    工具:上下文=。MapsActivity
    机器人:名字=com.google.android.gms.maps.SupportMapFragment/>

Goole_Maps_api.xml

 <字符串名称=google_maps_key翻译=假templateMergeStrategy =preserve>
        AIzaSyAnvkHr4CGYzmROT *******
    < /串>
< /资源>


解决方案

好吧,还有如果你遇到类似的情况,你应该注意两件事情:

1)有两个谷歌地图api.xml文件,一个版本,一个用于调试。
你可以在这些路径找到它们:

\\程序\\ SRC \\释放\\水库\\值

\\程序\\ SRC \\调试\\资源\\值

确认上添加这两个文件的谷歌地图的关键!

2)我没有找到官方消息此信息,但你需要生成除了常规的SHA1键释放文件的另一个SHA1密钥。

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

一旦你的文件发布新的密钥,在第二排它添加到您的谷歌API控制台已有的密钥。

Hi guyes I really need your help.

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

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

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

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.

What am I doing wrong?

Here is my code:

Manifest:

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

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

}

Main Activity Layout:

<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

 <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) 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\debug\res\values

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

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.

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

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

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

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