0

New developer but I have spent the past few days trying to resolve this problem of gray boxes showing up instead of a map on Android device.I have read just about everything there is to read about these boxes but the solutions that are working for other people are not working for me.

The api key that I am using comes from keytool in my java JRE 7 folder using the command from bin folder: keytool -list -alias androiddebugkey -keystore "C:\Users\ben.android\debug.keystore" -storepass android -keypass android -v .... I believe this is the debug API key that I have read about here as well as other places.

Here is the error I am getting http://imgur.com/IoHMHQc. I believe I have highlighted the "interesting" part which is java.io.IOException: Server returned: 3.

It seems like that means my API key is faulty but I have made multiple new ones and none seem to fix the problem! I am NOT uploading the application yet so I don't think the "signed/unsigned" exporting matters but that is because I don't understand it completely.

I have tried following multiple tutorials such as one from Lynda.com as well as various youtube tutorials, however they all are Google Maps v2 rather than v3 so that may be the issue. Help would be greatly appreciated and lifesaving!

Here is my main java file:

package com.bentseytlin.gmap2;

import com.google.android.maps.MapActivity;

import com.google.android.maps.MapView;

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

public class MainActivity extends MapActivity {

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

        MapView view = (MapView) findViewById(R.id.themap);
                view.setBuiltInZoomControls(true);

    }

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

}

Here is my xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_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

       android:layout_width="fill_parent"
       android:layout_height="fill_parent"    
       android:id="@+id/themap"
       android:clickable="true"
       android:apiKey="AIzaSyB1gqlqGQZCH1TlrDhp5BP9Pm9k4Jm_2co"
       />

</RelativeLayout>

And here is my Manifest File:

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

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <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.bentseytlin.gmap2.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>

Thanks again!

4

2 回答 2

1

确保您已按照以下链接中的所有步骤操作

https://developers.google.com/maps/documentation/android/start。(API v2)

您应该在地图项目中参考谷歌服务库项目

下载 Google Play 服务。转到 Windows。转到 Android SDK 管理器。在 extras 下选择 Google play services。如果未安装,请安装该软件包。

将 google-play services_lib 库项目复制到您的工作区。库项目可以在以下路径下找到。

 <android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib library project .

将库项目导入 Eclipse。

点击 File > Import,选择 Android > Existing Android Code into Workspace,浏览工作区导入库项目。您可以检查它是否是库项目。右键单击库项目。转到属性。单击左侧面板上的 Android。您将看到 Is Library 已选中。

参考图书馆项目

右键单击您的 android 地图项目。转到属性。选择安卓。单击添加 borwse 并添加库项目。

假设你有钥匙。

确保您已在服务选项卡下的 google api 控制台中启用 google maps for android。

你的 min sdk 是 10。你应该使用 Support Fragment。

<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"  
android:layout_width="match_parent"
android:layout_height="match_parent"/>

您的活动必须延长FragmentActivity

SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap(); 

确保您已添加支持库

还要确保您导入了以下内容

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment;    

在清单文件中添加这些

  <permission
    android:name="com.bentseytlin.gmap2.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
 <uses-permission android:name="com.bentseytlin.gmap2.permission.MAPS_RECEIVE"/>  
 <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>  

在应用程序标签下的清单中添加键

 <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="key"/>    
于 2013-06-13T21:09:14.563 回答
0

您正在尝试使用自 2012 年 12 月起弃用的 Google Maps Android API v1,并且自 2013 年 3 月起不适用于新项目。

切换到 API v2 的最简单方法是 1) 删除所有与地图相关的代码,2) 遵循此处的说明:https ://developers.google.com/maps/documentation/android/start 。

于 2013-06-13T21:08:56.503 回答