【问题标题】:Android - Maps Cannot showAndroid - 地图无法显示
【发布时间】:2023-03-31 10:51:01
【问题描述】:

我想在我的 android 应用程序上显示谷歌地图。显示我做了一些这样的基本步骤:

AndroidManifest.xml

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

maps.xml

<view android:id="@+id/mv"
        class="com.google.android.maps.MapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" 
        android:clickable="true"
        android:apiKey="0cNoErXkpZDlKvCYr_OFj5xZD39-***********"
    />

这可能是映射类、导入和 onCreate 方法

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

地图类上的 onCreate() 方法

    public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.maps);

    mapView = (MapView)findViewById(R.id.mv);
    mapView.setSatellite(false);
    mapView.setTraffic(false);
    mapView.setBuiltInZoomControls(true);

    int maxZoom = mapView.getMaxZoomLevel();
    int initZoom = maxZoom-2;

    mapControl = mapView.getController();
    mapControl.setZoom(initZoom);

    latE6 = (int) (lat*1e6);
    lonE6 = (int) (lon*1e6);
    gp = new GeoPoint(latE6, lonE6);
    mapControl.animateTo(gp);

    overlayButton = (Button)findViewById(R.id.doOverlay);

但是为什么我的地图没有显示,我只看到没有地图的网格,当我尝试读取 logcat 时,我看到这个黄色错误

Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@40563470

请帮助我。谢谢老哥

【问题讨论】:

    标签: android google-maps android-maps


    【解决方案1】:

    您确定您的 API 密钥正确吗?当 API 密钥不匹配时,它会显示网格而不是地图。

    在模拟器/实际手机上直接从 Eclipse 运行应用程序需要一个不同的密钥,然后当您首先构建 .apk 文件并在设备上运行它时。

    【讨论】:

    • 我确定我的 API 密钥是正确的。我尝试请求新的 API 密钥并设置为我的 android 应用程序.. 但它仍然提供网格视图 >_
    • 您是直接从 Eclipse 运行应用程序,还是先将其导出,然后将其作为 apk 安装在手机上?如果您从 Eclipse 运行它,请尝试构建它并将其安装在您的手机上。您的错误是典型的 api-key 问题。
    • 我直接在我的笔记本电脑和我的 Eclipse IDE 上运行我的应用程序。我没有导入/导出或在不同的设备上运行。在我尝试编写该代码之前,我的地图显示正常,带有简单的地图。然后我尝试制作覆盖按钮并显示来自纬度和经度的路线,然后我尝试在我的模拟器中运行。但我看到的只是一个网格,没有像以前那样的地图。 @Sander 感谢您与需要帮助的讨论@_@
    • 如何处理来自 log cat "Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@40563470" 的错误
    • 嗯,对不起,我真的不知道。我看不出您的代码有任何问题,尝试添加叠加按钮不会导致这样的问题。不过我会密切注意这一点,如果我有任何想法,我会告诉你。
    【解决方案2】:

    -如果您有 Internet over proxy,您将获得 grids 。 - 使用默认调试密钥库生成 API 密钥并尝试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多