2

I am creating an android application that uses google maps api v2. I believe I have done everything as google tutorial sais but still I am getting only the google maps grid (no map). I have created a debug key from using SHA1 of keystore.debug.

below are my settings: Eclipse java compiler version 1.7 Project java compiler version 1.6

application manifest:

<manifest ...>
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="my.app.test.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application>
        <activity>
        ...
        </activity>
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="xxxxxxxxxxxxxxxxxxxxxxxxxx"/>

        <uses-library android:name="com.google.android.maps"/>
    </application>

</manifest>

Map xml:

<LinearLayout 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:background="@color/BackGroundColor"
    android:orientation="vertical"
    tools:context=".test" >

     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingRight="10dp"
        android:paddingTop="5dp" >

        <com.google.android.maps.MapView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/mapview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clickable="true"
            android:apiKey="xxxxxxxxxxxxxxxxxxxxxxxxxx" >
        </com.google.android.maps.MapView>

    </LinearLayout>
</LinearLayout>

Map Activity:

public class Map extends MapActivity {
MapView mapView; 
MapController mc;
      GeoPoint p;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.activity_map);

    mapView = (MapView) findViewById(R.id.mapview); 
                mapView.setBuiltInZoomControls(true); 
                mapView.setStreetView(true);


                mc = mapView.getController();
                String coordinates[] = {"1.352566007", "103.78921587"};
                double lat = Double.parseDouble(coordinates[0]);
                double lng = Double.parseDouble(coordinates[1]);

                p = new GeoPoint(
                      (int) (lat * 1E6), 
                      (int) (lng * 1E6));

                mc.animateTo(p);
                mc.setZoom(17); 
                mapView.invalidate();
}

      @Override
      protected boolean isRouteDisplayed() { return false; }

}

I know that there are plenty of post with the same problem. I have read them all!!! I have created the key several times but still the same... Any ideas what is wrong and I am only seeing the grid? the application has the same outcome to AVD as well as to a Samsung mobile with android version 2.2.1

Reven
  • 609
  • 3
  • 9
  • 17
  • You definitely generated the Key incorrectly this is the main cause of this issue, you need to follow all the steps to generate a key again from the beginning. – Shehabic Apr 01 '13 at 06:19
  • I have generated the key several times in many different ways. I had also installed jdk 1.6 in order to create the key from that version since I had read some posts that was reffering to that. what could possible went wrong to key generation? – Reven Apr 01 '13 at 06:29
  • I have also tried to create my own certificate, create a new key from the sha1 of that certificate and sign/export the apk. then I installed the application to my android phone. I still get an empty map with only the grid and the zoom panel. Thus I lean to believe that there is something wrong with the code...any ideas? – Reven Apr 01 '13 at 07:52

3 Answers3

2

If you writing you application for API V2 then you are using the wrong objects, few things you need to fix:

1. Remove this:

<uses-library android:name="com.google.android.maps"/>

it's a permission for Google Map API V1.

2. you have to add this 2 permissions:

<permission android:name="your.application.package.permission.MAPS_RECEIVE"    android:protectionLevel="signature"/>
<uses-permission android:name="your.application.package.permission.MAPS_RECEIVE"/>

change: your.application.package to your current application package.

3. As you targeting SDK v8, you have to add fragment support to your application in order to use the SupportMapFragment from Google Map API V2, So you need to add google-support-v4 and change your map object to SupportMapFragment.

4. Your MapActivity has to be changed to FragmentActivity.

5. You can can get more information on how to make those changes in a blog post I wrote on how to add Google Map API V2 to your project:

Google Maps API V2

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
1

Your problem is related with the emulator, you need to install to APK's. I had similar problems so I prepared step by step tutorial to show how you can use google map android v2 on emulator(android 4.2.2) have a look at to my blog: http://umut.tekguc.info/en/content/google-android-map-v2-step-step

Umut Tekgüç
  • 551
  • 3
  • 2
0

You need to generate MD5 fingerprint from java keytool instead of SHA1. Check this post to generate MD5 fingerprint: How can I get the MD5 fingerprint from Java's keytool, not only SHA-1?

Community
  • 1
  • 1
M.J
  • 586
  • 6
  • 16
  • MD5 is needed for api v1 not for api v2. I have tried it and the google console api was returning an error. – Reven Apr 01 '13 at 06:40