【问题标题】:Android Map NOT showing. Only GridsAndroid 地图未显示。只有网格
【发布时间】:2015-04-07 03:52:03
【问题描述】:

问题已解决 解决方案的简短摘要:确保您不是 api v1 的类。现在当我工作时,模拟器对测试应用程序毫无用处。所以在实际设备上进行测试。 最后,如果应用程序运行正确但不显示地图,那么您的密钥有问题。 我在这里注意到的是 catlog 并没有说 key 错误,应用程序运行,但 map 没有显示。

我正在尝试 2 天来制作一个简单的 Google 地图 Android 应用程序,该应用程序仅在 Activity 上显示地图但失败了。尝试了每个教程,直到谷歌的第二页。没有任何效果。起作用的只是我在书中关注的应用程序,但它显示网格并且没有 MAP。通常人们会给出钥匙错误的答案,但事实并非如此。我的密钥是正确的,我在生成密钥方面工作准确。 我正在使用 Google Maps Android API v2 密钥。

这是我的 activity_main.xml

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

    <com.google.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="0AeGR0UwGH4pYmhcwaA9JF5mMEtrmwFe8RobTHA"
        android:clickable="true"
        android:enabled="true" />

</LinearLayout>

这是我的 MainActivity.java

package com.example.lbs;

import android.os.Bundle;
import android.view.Menu;

import com.google.android.maps.MapActivity;

public class MainActivity extends MapActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

}

这是我的 AndroidManifest.xml

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

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

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

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

    <permission
        android:name="com.example.lbs.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.lbs.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <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" />

    <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" />

        <activity
            android:name="com.example.lbs.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>

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

</manifest>

在 catlog 上,当应用程序运行时,我得到了这个

IOException processing: 26
java.io.IOException: Server returned: 3
    at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)

更新 1: 综上所述,正如我在某些地方所读到的,代码可能仅适用于 API 密钥 v1。所以我从https://blog-emildesign.rhcloud.com/?p=435开始完全遵循了一个教程 我最终得到了这个

更新 2: 现在我试图让它在实际的 Android 设备上运行。这是安卓2.3。 所以做更多的工作。我最终参加了我的活动

而我在 CatLog 上可以看到的是

所以地图还没有显示...请帮助...

更新 3: 问题出在 API 密钥中。我在 logcat 中看不到任何关于错误键的信息。应用程序运行但不显示地图。所以我重新生成了密钥。 现在我们开始

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    您的问题是您生成了 Google Maps API V2 的密钥,但您尝试使用 Google Maps API V1 对象MapView

      <com.google.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="0AeGR0UwGH4pYmhcwaA9JF5mMEtrmwFe8RobTHA"
        android:clickable="true"
        android:enabled="true" />
    

    相反,您应该使用MapFramgentSupportMapFragment,具体取决于您所针对的 API 级别,您可以在我就此事撰写的本指南中获得有关如何在您的应用程序中集成 Google Maps API V2 的完整说明:

    Google Maps API V2

    更新:

    第二个屏幕截图是你想在模拟器上得到的。 Google Play Services 没有安装在模拟器上,这就是你看到你所看到的原因。尝试在安装了Google Play Services 的设备上测试此应用,它应该可以工作。

    【讨论】:

    • 在你回答的同时,我已经按照教程进行了操作,我得到了什么样的结果,你可以在我问题的最后一部分。我编辑了问题。请看我问题的最后一部分。
    • 您不认为按照本教程blog-emildesign.rhcloud.com/?p=527 并安装教程中提到的那些apk 文件可以使其在此模拟器上运行吗?
    • 它应该但不与您正在使用 Android SDK 管理器下载的当前 Google Play 服务库一起使用。如果你关注这篇文章中的 cmets,你会发现这个链接:venomvendor.blogspot.co.il/2012/03/… 如果你从那里下载修订版 4 并将它用于你的项目以及在模拟器上安装这些文件,那么它应该可以工作。
    • 现在我已经在实际的 android 设备上进行了尝试,并且应用程序正在运行。但不显示地图。请查看我的问题编辑的最后 2 张图片(我的问题中的 Update-2)。
    • 现在问题出在 API 密钥上。我重新生成了它并且它起作用了。谢谢
    【解决方案2】:

    检查一下! 我也有类似的问题。这对我有用! 1)转到Google API Console,是否生成了API密钥。 2)单击服务(出现在左侧的选项中)。 3)悬停并搜索 Google Maps Android API v2。 4)启用它(最初它是关闭的,因此只出现了灰色瓷砖)。

    【讨论】:

      【解决方案3】:

      在 Google API 控制台中,在您的 Android 应用密钥下,确保您添加了两个指纹 - 调试指纹和发布指纹。

      【讨论】:

      • 它要求提供 sha1 代码和包名。我插入了它,控制台给了我钥匙。我还缺少什么吗?
      • 有两种不同的 sha1,一种用于应用程序的发布版本(位于您的密钥库中),另一种用于调试版本(位于 ~/.android/debug.keystore)。在发布密钥之后也添加调试。前段时间我在做第一个地图应用程序时遇到了类似的问题,这就是原因。
      • 现在我得到了密钥后,我在控制台中看不到任何按钮或文本框来添加另一个密钥。从现在开始,我只想让它在模拟器上运行。而已。那么如果你认为有必要,那我应该如何添加其他键呢?
      • 使用“编辑允许的 Android 应用”链接。
      猜你喜欢
      • 1970-01-01
      • 2015-11-06
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多