user572575
user572575

Reputation: 1049

Google Map API V2 not show map on android

I try to learn Google Map API from this tutorial. I create package name like in tutorial which in a half of tutorial changes code in xml files only not do anything in java file. when I run my project it have no error. But it show grey background not show the map. I check API KEY and I think it ok which I use sha1 follow with ;package name and then it show API KEY like this

API key: AIzaSyC3B722X4KNSr3Ah-QIQEAhjJOYq0SCsRI

Android apps: 79:77:3E:70:B0:2E:75:99:62:6E:2D:DF:DB:1A:41:C3:5D:2D:52:67;ca.sfu.cmpt276.bfraser

This is my code

activity_main.xml

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

<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

<fragment
android:id="@+id/map"
android:layout_below="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>


</RelativeLayout>

Manifest

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

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

<permission
android:name="ca.sfu.cmpt276.bfraser.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="ca.sfu.cmpt276.bfraser.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"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<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="AIzaSyC3B722X4KNSr3Ah-QIQEAhjJOYq0SCsRI"/>


<activity
android:name="ca.sfu.cmpt276.bfraser.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>

How to use Google Map API show map in android?

Upvotes: 0

Views: 2825

Answers (2)

Edson H Philippe
Edson H Philippe

Reputation: 527

From my experience, this happen when you did not setup your key correctly. either you changed the package name and are unaware of it. I had the same problem. To solve it, I first took a look at the console while the application was running on my android emulator. In it, it throws and error saying the app was not communicating with Google. Here is the easiest way to fix this issue.

Wash this video: https://www.youtube.com/watch?v=vgr4l1nsFdU

from it, you will realize what you might have done wrong. From the Google tutorial, it says to use keytool -list -v -keystore "%USERPROFILE%.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android. I think that might be where you got it wrong.

Upvotes: 1

Raghunandan
Raghunandan

Reputation: 133560

Your min sdk is 8. 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;    

Upvotes: 1

Related Questions