谷歌地图在android系统只显示网格 [英] google map in android display only grid

查看:177
本文介绍了谷歌地图在android系统只显示网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现谷歌地图,但我面临着一些问题的。
问题是,当我打开我的应用程序只显示在地图上(而不是地图的图像)的网格。

下面是我的code ...任何人都可以看到这个问题?

XML主要

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直>    <的TextView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=@字符串/你好/>    < com.google.android.maps.MapView
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@ + ID / map_view
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:apiKey =API密钥
        机器人:可点击=真
        机器人:启用=真/>    < / LinearLayout中>

清单文件

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=info.org.NewMap
    安卓版code =1
    机器人:=的versionName1.0>    <采用-SDK安卓的minSdkVersion =8/>
    <使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
    <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
    <应用
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME>
        <活动
            机器人:名字=。NewMapActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        <使用库机器人:名字=com.google.android.maps/>
    < /用途>< /清单>

的Java类

 包info.org.NewMap;进口android.os.Bundle;
进口com.google.android.maps.MapActivity;
进口com.google.android.maps.MapView;
公共类NewMapActivity扩展MapActivity {
    / **当第一次创建活动调用。 * /    私人MapView类MapView类;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);        图形页面=(图形页面)findViewById(R.id.map_view);
        mapView.setBuiltInZoomControls(真);
    }    @覆盖
    保护布尔isRouteDisplayed(){
        // TODO自动生成方法存根
        返回false;
    }
}

二Java文件

 包info.org.NewMap;
进口的java.util.ArrayList;
进口android.app.AlertDialog;
进口android.content.Context;
进口android.graphics.drawable.Drawable;
进口com.google.android.maps.ItemizedOverlay;
进口com.google.android.maps.OverlayItem;公共类CustomItemizedOverlay扩展ItemizedOverlay< OverlayItem> {    私人的ArrayList< OverlayItem> mapOverlays =新的ArrayList< OverlayItem>();    私人上下文的背景下;    公共CustomItemizedOverlay(可绘制defaultMarker){
        超(boundCenterBottom(defaultMarker));
    }    公共CustomItemizedOverlay(可绘制defaultMarker,上下文的背景下){
        这个(defaultMarker);
        this.context =背景;
    }    @覆盖
    保护OverlayItem createItem中(int i)以{
        返回mapOverlays.get(ⅰ);
    }    @覆盖
    公众诠释大小(){
        返回mapOverlays.size();
    }    @覆盖
    保护布尔中的onTap(INT指数){
        OverlayItem项目= mapOverlays.get(指数);
        AlertDialog.Builder对话框=新AlertDialog.Builder(背景);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());
        dialog.show();
        返回true;
    }    公共无效addOverlay(OverlayItem叠加){
        mapOverlays.add(覆盖);
        this.populate();
    }
}


解决方案

如果您已经使用debug.keystore来获取地图API密钥,那么它不会显示的地图瓦片,当你启动用自己专用的密钥库签署的应用程序。
你已经签署您的应用程序?

要在地图应用程序签署必须使用你已经用来签名的应用程序(不debug.keystore)相同的密钥库获得谷歌API密钥。

I am trying to implement Google Map but I am facing some problem with it. The problem is that when I load my app it displays only the grid of the map (not an image of the map).

Here is my code... can anyone see the problem?

Xml Main

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

Manifest File

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

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;
    }
}

Second Java File

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();
    }
}

解决方案

If you have used debug.keystore to get api key for map then it will not show map tiles when you launching signed the app with your own private keystore. Have you signed your app ?

To work map in signed app you must get api key from google using same keystore that you have used to sign the app(not debug.keystore).

这篇关于谷歌地图在android系统只显示网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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