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 https://i.stack.imgur.com/qaHfy.jpg. 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!

Community
  • 1
  • 1
benzabill
  • 259
  • 1
  • 8
  • 21
  • Have you activated the Google Maps API v3 for your key in the API console? – Dom Jun 13 '13 at 20:50
  • 1
    [Google map signed api key errors in Android](http://stackoverflow.com/a/8989312/1693859) – Sam R. Jun 13 '13 at 20:52
  • http://stackoverflow.com/questions/15678344/mapview-in-android-application – Morrison Chang Jun 13 '13 at 20:55
  • @DominicB-c, what does that mean exactly? I copied the API-key from the Google Dev site into my manifest but that is all I have done – benzabill Jun 13 '13 at 20:56
  • are you using google map api v2? – Raghunandan Jun 13 '13 at 20:58
  • Click on 'services' in the menu to the left of the console where you find your API key, find the API you want to use and turn it on. – Dom Jun 13 '13 at 20:59
  • @Raghunandan, I believe that I am using v3. Has mapview been deprecated or something? Should i be using mapfragment? – benzabill Jun 13 '13 at 21:01
  • @DominicB-c, yes i have activated that. As i wrote above, am i not supposed to be using mapview? – benzabill Jun 13 '13 at 21:02
  • @benzabill https://developers.google.com/maps/documentation/javascript/ api v3 uses java script. so what version are you using? – Raghunandan Jun 13 '13 at 21:03
  • @Raghunandan, I am working in Eclipse with android SDK. I guess I was using a v3 apikey with v2 coding? How do i see what version i am using. Also: I tried using v2 key and it still didnt work – benzabill Jun 13 '13 at 21:06
  • if you use version 2 check the link https://developers.google.com/maps/documentation/android/start. use should use fragments – Raghunandan Jun 13 '13 at 21:06
  • I just confused myself. So I am trying to get google maps for android phones (mobile application) so that means that I should be using "Google Maps Android API v2" correct? (I had been using Google Maps API v3 (and then about 5 minutes ago v2)). Also, is javascript basically required now? I thought that I could do this in eclipse with this android sdk in java language. thank you so much by the way! – benzabill Jun 13 '13 at 21:11
  • @benzabill forget everything start here developers.google.com/maps/documentation/android/start. – Raghunandan Jun 13 '13 at 21:12

2 Answers2

1

Make sure you have followed all the steps in the below link

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

You should refer to google services library project in your map project

Download the Google Play services.Goto Windows. Goto Android Sdk Manager. Choose Google play services under extras. If not installed install the package.

Copy the google-play services_lib library project to your workspace. The library project can be found under the following path.

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

Import the library project to your eclipse.

Click File > Import, select Android > Existing Android Code into Workspace, and browse the workspace import the library project. You can check if it is library project. Right click on the library project. Goto properties. Click Android on the left panel. You will see Is Library checked.

To refer to the library project

Right click on you android map project. goto properties. Choose Android. Click Add borwse and add the library project.

Assuming you have the key.

Make sure you have enabled google maps for android in the google api console under the services tab.

Your min sdk is 10. You should use Support Fragment.

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

Your activity must extend FragmentActivity

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

Make sure you have added support library

Also make sure you imported the below

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

Add these in manifest file

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

Add the key in manifest under application tag

 <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="key"/>    
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

You are trying to use Google Maps Android API v1, which is deprecated since december 2012 and will not work for new projects since march 2013.

The easiest way to switch to API v2 is by 1) removing all your code related to maps, 2) following instructions here: https://developers.google.com/maps/documentation/android/start.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94