【问题标题】:google map in android display only gridandroid中的谷歌地图仅显示网格
【发布时间】:2012-06-22 13:22:17
【问题描述】:

我正在尝试实施 Google 地图,但我遇到了一些问题。 问题是当我加载我的应用程序时,它只显示地图的网格(而不是地图的图像)。

这是我的代码...谁能看到问题?

Xml 主要

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <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:apiKey=" api key"
        android:clickable="true"
        android:enabled="true" />

    </LinearLayout>

清单文件

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

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>


    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".NewMapActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <uses-library android:name="com.google.android.maps" />
    </application>

</manifest>

Java 类

package info.org.NewMap;

import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class NewMapActivity extends MapActivity {
    /** Called when the activity is first created. */

    private MapView mapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

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

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

第二个 Java 文件

package info.org.NewMap;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();

    private Context context;

    public CustomItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
    }

    public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
        this(defaultMarker);
        this.context = context;
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mapOverlays.get(i);
    }

    @Override
    public int size() {
        return mapOverlays.size();
    }

    @Override
    protected boolean onTap(int index) {
        OverlayItem item = mapOverlays.get(index);
        AlertDialog.Builder dialog = new AlertDialog.Builder(context);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());
        dialog.show();
        return true;
    }

    public void addOverlay(OverlayItem overlay) {
        mapOverlays.add(overlay);
        this.populate();
    }
}

【问题讨论】:

  • 您是否提供了正确的地图 api 密钥
  • 是的,你的正确问题是 api 密钥..

标签: android google-maps


【解决方案1】:

如果您已使用 debug.keystore 获取地图的 api 密钥,那么当您启动使用您自己的私钥存储签名的应用程序时,它不会显示地图图块。 你签署了你的应用程序吗?

要在已签名的应用程序中工作地图,您必须使用与您为应用程序签名相同的密钥库(不是 debug.keystore)从谷歌获取 api 密钥。

【讨论】:

  • 谢谢亲爱的,我的问题已经解决了,但是我从 debug.keystore 构建了 api 密钥,它运行良好。
  • +1 你是对的,如果我从 debug.keystore 创建我的 api 密钥,它可以工作,但是当我创建我的应用程序的 APK 时,它会产生问题,所以我必须使用我的应用程序密钥库创建谢谢...
【解决方案2】:

您是否在 AndroidManifest.xml 文件中为您的应用程序添加了以下权限

  1. 互联网
  2. ACCESS_FINE_LOCATION
  3. ACCESS_COARSE_LOCATION

问候, 阿基夫·哈米德

【讨论】:

    【解决方案3】:

    禁用代理服务器..如果启用代理服务器,地图将无法工作..

    【讨论】:

    • 一个人怎么能做到这一点,它与任何事情有什么关系?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多