0

The goal I am trying to achieve is simply display a map.

I know this question has been asked earlier and i have followed the threads and tutorials but I see nothing when I try the following. Is there a mistake in my code somewhere?

Is my code correct to work with the latest Map API?

My java launcher source file:

package com.devmav.mapstest;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@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;
}

}

My Layout XML file:

<?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"
class="com.google.android.gms.maps.SupportMapFragment"/>

My AndroidManifest.xml:

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

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

<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="<I ENTERED MY API KEY HERE FROM GOOGLE CLOUD CONSOLE: https://cloud.google.com/console/project"/>

    <activity
        android:name="com.devmav.mapstest.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>

UPDATE 1: After adding Google Services in the AndroidManifest.xml, I see a blank screen for the map.

enter image description here

UPDATE 2: I have added permissions correctly to my app. I am quite certain i have added the SHA1 fingerprint and application namespace correctly for the app too.

enter image description here

user1406716
  • 9,565
  • 22
  • 96
  • 151

4 Answers4

1

You are missing

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

in the application tag of manifest.

Make sure you have referenced the library project properly. Make sure you have enabled maps for android in the google api console and you have the right.

See if you have followed all the steps mentioned in the below link and you should see the map.

Lastly test in a device that has google play services installed.

https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2

Converting comment to answer

Try to re-generate the API key.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
1

Simply add this in your application tag in manifest file:

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

Or else follow this link which I answered previously.

Community
  • 1
  • 1
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
  • I made the change, I see the a blank map with the +(zoom in) & -(zoom out) buttons but no actual water or landmass in the map. I updated the question with a screenshot. I am on Galaxy S3. – user1406716 Jan 21 '14 at 10:58
  • 1
    Have you enabled Google maps android api v2 in api console? – Shailendra Madda Jan 21 '14 at 11:00
  • 1
    And also make sure your api key is generated in API Console with your sha1+package name which is mentioned in Android Manifest.xml file.If still getting same let me know.. – Shailendra Madda Jan 21 '14 at 11:04
  • Yes, I made sure of the same for both items, enabling api v2 in console and also sha1+package name. – user1406716 Jan 21 '14 at 11:06
  • 1
    @user1406716 re-generate the api key and try again – Raghunandan Jan 21 '14 at 11:07
  • @Raghunandan - Regenerating the api key did the trick, thanks to you & shylendra for the help. Marking Raghunandan's comment as +1 and shylendra's as answer. thanks again. – user1406716 Jan 21 '14 at 11:13
0

Try to add Google play Services as a reference library...

in you manifest file

    <permission
        android:name="com.example.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
        <uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
vinay Maneti
  • 1,447
  • 1
  • 23
  • 31
  • 3
    this permission is not required. check uses permission https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2 – Raghunandan Jan 21 '14 at 10:38
0

use this:

public class MainActivity extends FragmentActivity {

 final int RQS_GooglePlayServices = 1;
 private GoogleMap myMap;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

   FragmentManager myFragmentManager = getSupportFragmentManager();
   SupportMapFragment mySupportMapFragment 
    = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
   myMap = mySupportMapFragment.getMap();

 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
     case R.id.menu_legalnotices:
      String LicenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(
        getApplicationContext());
      AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(MainActivity.this);
      LicenseDialog.setTitle("Legal Notices");
      LicenseDialog.setMessage(LicenseInfo);
      LicenseDialog.show();
         return true;
     }
  return super.onOptionsItemSelected(item);
 }

 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();

  int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

  if (resultCode == ConnectionResult.SUCCESS){
   Toast.makeText(getApplicationContext(), 
     "isGooglePlayServicesAvailable SUCCESS", 
     Toast.LENGTH_LONG).show();
  }else{
   GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices);
  }

 }

}

and this is for main activity:

<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"
    tools:context=".MainActivity" >

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

</RelativeLayout>
Mohammad Rababah
  • 1,730
  • 4
  • 17
  • 32