java - Google map 在 Android 应用程序中不显示图 block

标签 java android google-maps

我知道此类问题已被问过很多次,但我真的很困惑,不知道我的错误/错误在哪里。当我运行该应用程序时,我的 map 显示在我的模拟器和 Samsung Galaxy 3 上,但它显示的所有内容都是可以放大或缩小的灰色图 block 。

这是我的 list 文件

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

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="17"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permisison 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-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <uses-library android:name="com.google.android.maps" />

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="A#####################################4" />

    <activity
        android:name="com.android.maptesting.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</application>

</manifest>

这是我的布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_view"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_below="@+id/tridView"
    android:layout_centerHorizontal="true"
    android:clickable="true" 
    android:enabled="true" 
    android:apiKey="A####################################4" />

</RelativeLayout>

最后是我的 java 文件

package com.android.maptesting;

import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {

    private MapView mapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mapView = (MapView) findViewById(R.id.map_view);       
        mapView.setBuiltInZoomControls(true);
    }

    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

}

然后,当应用程序在 Galaxy S3 上“运行”时,所有 logcat 都会显示:

Couldn't get connection factory client
IOException processing: 26
java.io.IOException: Server returned: 3
at     android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileReuqest.readResponseData(BaseTileRequest.java.115)
at     android_maps_conflictavoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)

并且会定期重复这一点。这意味着我的应用程序正在尝试获取图 block 但没有成功。

通过查看论坛和其他 stackoverflow 问题,常见问题出现在 list 文件的权限中。老实说,我相信我拥有一切。下一个常见问题是 API key 。我确实对此感到有点困惑,但完全遵循了教程和其他人的步骤。不过,当最终给出 key 时,谷歌要求提供 SHA-1,而不是其他人似乎使用的 MD5。我确实尝试过 MD5,但 google 并没有将其视为获取 key 的有效响应。

我正在尝试使用“Google Maps Android API v2”,在获取 key 时我使用“创建新的 Android key ”并使用我的 SHA-1 后跟“;”然后是我的包名。为了获得 SHA-1,我按照此分步说明进行操作 > https://stackoverflow.com/a/11493316/1833809 (是的,我知道它说的是 MD5,但我使用 -v 选项来查看所有指纹)。

说实话,如果某个地方出现愚蠢或简单的错误,我会很高兴,因为我已经为此苦苦挣扎了几天并失去了耐心。因此,对于可能重复出现此类问题,我再次表示歉意,但其他解决方案似乎对我没有帮助。

最佳答案

坦率地说,这看起来确实是一个关键问题。首先,我建议您仔细阅读我写的关于获取 Google Map API V2 key 和创建 Google map 的两篇文章:

Google Maps API V2

Getting Key for Google API

如果这些指南无法帮助您,根据我的经验,您可以尝试删除当前的: C:\Users\"Your username"\.android 目录中的 debug.keystore 文件。

并运行 Android 项目的编译来重新创建它。

接下来再次尝试按照 key 指南进行操作,因为您将收到新的 SHA1 key 。

关于java - Google map 在 Android 应用程序中不显示图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15364401/

相关文章:

Java 和设置类路径以及包的本地化

java - 应用程序被强制关闭

java - 如何在 cucumber 中重新运行失败的方案

android - 如何在 Android Studio 中更改项目名称

Android proguard 不会混淆类

android - 构建 FragmentStatePagerAdapter、ViewModel 和 Fragment 列表

html - 两个谷歌地图重叠

javascript - 谷歌地图上 GeoJSON 功能上的测地线

java - 如何在不使用任何库的情况下用Java创建图形对象?

java - 无论文本大小如何,始终在 JButton 内显示文本