Reputation: 524
I'm trying to create and application that connects with Google maps. But when the screen loads where the map should be its just grey. How do I fix this?
The important message from my logcat.
06-11 03:32:55.196: E/Google Maps Android API(11671):
Ensure that the following correspond to what is in the API Console: Package Name: my pacakage,
API Key: my key,
Certificate Fingerprint: my fingerprint
The Activity
import android.os.Bundle;
import android.view.Menu;
import android.support.v4.app.FragmentActivity;
public class mapPage extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_page);
}
@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;
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="my package.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="my package.permission.MAPS_RECEIVE"/>
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- End of copy. -->
<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="my key"/>
<activity
android:name="my package.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>
<activity android:name=".main">
</activity>
<activity android:name=".mapPage">
</activity>
<activity android:name=".ThirdPartyWeb"
android:theme="@android:style/Theme.Dialog">
</activity>
</application>
</manifest>
The layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_height="250dp"
android:layout_width="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
<ImageView
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_height="50dp"
android:layout_width="fill_parent"
android:background="@color/darkGrey"/>
<Button
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"
android:id="@+id/menuButton"
android:background="@drawable/icon_menu"
android:layout_height="30dp"
android:layout_width="30dp"/>
<Button
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/menuButton"
android:layout_marginLeft="20dp"
android:id="@+id/"
android:background="@drawable/icon_off"
android:layout_height="35dp"
android:layout_width="55dp"/>
<EditText
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/"
android:layout_marginLeft="20dp"
android:layout_toEndOf="@+id/"
android:id="@+id/seachBox"
android:hint="@string/search"
android:layout_height="35dp"
android:layout_alignParentEnd="true"
android:background="@color/white"/>
<Button
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:id="@+id/searchButton"
android:background="@drawable/graphic_search"
android:layout_height="35dp"
android:layout_width="20dp"/>
<ImageView
android:layout_above="@+id/newsFeed"
android:layout_centerInParent="true"
android:layout_height="35dp"
android:layout_width="fill_parent"
android:background="@color/darkGrey"/>
<TextView
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_above="@+id/newsFeed"
android:layout_marginBottom="11dp"
android:textColor="@color/white"
android:text="@string/news_feed"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<ListView
android:layout_alignParentBottom="true"
android:id="@+id/newsFeed"
android:layout_width="fill_parent"
android:layout_height="wrap_content">"
</ListView>
</RelativeLayout>
Upvotes: 6
Views: 13462
Reputation: 558
I had the same problem but for me the app stopped working. I found out that it was problem with debug.keystore that Eclipse generate. It may happens when:
debug.keystore
is get from local directory USER_DIR.android\debug.keystore
debug.keystore
USER_DIR.android\debug.keystore
somehowTo confirm this problem get SHA1 from your USER_DIR.android\debug.keystore
and compare with the one from Android Console. They must be the same. If not try to generate new Key for Android apps by following this guide.
Once you get it then update your AndroidManifest.xml
file
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="NEW_API_KEY"/>
and clean whole ./bin
directory. Make it manually, don't trust Project -> Clean... option in Eclipse. Uninstall app from device before installing new one.
To avoid this problem in the future add your debug keystore to repo. Keep release in secret.
Upvotes: 0
Reputation: 524
Ok problem solved. On the google api console, there is two google map api v2's. I had the one just for google maps api v2 if you look just above it, it says google maps v2 android. I turned on that one as well and the map is running.
Upvotes: 11
Reputation: 6899
There are two mode. release mode and debug mode, if you want to use in release mode, then u want to custom create fingure print. debug mode is usual mode.
https://developers.google.com/maps/documentation/android/start#obtaining_an_api_key
See Displaying the release certificate fingerprint and debug certification fingure print in doucmentation
Upvotes: 1
Reputation: 41139
As it looks from the error, it seems that your configurations in the Google's API Console is wrong. Take a look at this blog post I wrote and make sure you are doing all the steps correctly:
Upvotes: 4
Reputation: 7226
@rajwant rai: maybe your code is for API v1, because I use API v2 and such code is not necessary.
@author: Do you test it on the phone or emulator. Phone must have some google services installed for the map to work. How to prepare working project is more described here: https://developers.google.com/maps/documentation/android/start
Upvotes: 1
Reputation: 477
try to add following to manifest file (after meta-data tag)
<uses-library
android:name="com.google.android.maps"
android:required="true" />
Upvotes: 0