Lawrence Barse
Lawrence Barse

Reputation: 120

Google Map APi v.2 not working

I'm a beginner trying to use Google Map API v.2, I've followed the following example,

http://www.vogella.com/articles/AndroidGoogleMaps/article.html

I know it wont work on the emulator, so I packaged the app as a Signed App and installed it on my CellPhone. But the app wont show the Map. Please Help

Here's my Manifest file

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

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />
    <permission
            android:name="com.example.maptest.permission.MAPS_RECEIVE"
            android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.maptest.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="false"/>
    <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.example.maptest.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>
        <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="MAP_KEK"/>
    </application>
</manifest>

My Layout XML

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>

And my JAVA code

package com.example.maptest;


import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends Activity {

    static final LatLng HAMBURG = new LatLng(53.558, 9.927);
    static final LatLng KIEL = new LatLng(53.551, 9.993);
    private GoogleMap map;
    private ProgressDialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dialog = new ProgressDialog(MainActivity.this);
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        if (map!=null){
        Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG).title("Hamburg"));
       Marker kiel = map.addMarker(new MarkerOptions().position(KIEL).title("Kiel").snippet("Kiel is cool").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
            this.dialog.setMessage("Loading Map Please Wait...");
            this.dialog.show();
          }
        else if(map == null)
        {
            this.dialog.setMessage("Unable to fetch map");
            this.dialog.show();
        }
    }
}

As you can see, I've added dialog's to indicate if Map Object is available or not.

Upvotes: 0

Views: 296

Answers (4)

user2570516
user2570516

Reputation: 31

It seems that you are missing API key. To do that you need to have SHA1 fingerprint(digital certificate) which must be used to retrive API key for your application so that you can use Google Maps. API key looks like this: AIzaSyDrav17-m1w7W17Gq19gOGvodfbnhyWQRF .It is 40 character long and is unique for your application. After you retrieve this key put it in android:value attribute. Refer to the documentation here.Hope this helps.

Upvotes: 0

Tai Dao
Tai Dao

Reputation: 3437

Try to fix manifest:

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

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />
    <permission
            android:name="com.example.maptest.permission.MAPS_RECEIVE"
            android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.maptest.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="false"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="MAP_KEK"/>
       <!-- <uses-library
        android:name="com.google.android.maps" />-->
        <activity
            android:name="com.example.maptest.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>

and turn your google map api v2 services at google console like this

Upvotes: 0

Bhavesh Patadiya
Bhavesh Patadiya

Reputation: 25830

I packaged the app as a Signed App and installed it on my CellPhone. But the app wont show the Map

Make Sure you have set the API key which is from same keystore you are using to signed your application.

Upvotes: 1

Justin Reda
Justin Reda

Reputation: 91

You are missing a Maps APi key. Please see this page for details on how to obtain the key and use it. https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key

The emulator will never work unfortunately (just doesn't work with maps yet) so make sure that if you are signing the app, you generate a key based off of your signature keystore, not the debug keystore.

Upvotes: 0

Related Questions