Aldridge1991
Aldridge1991

Reputation: 1367

Display maps Android api V2

I'm triying to show a map in my app with the new api but all what i get is:

"Uknown issue with Google Play Services"

This is my manifest:

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

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

<uses-permission android:name="android.permission.INTERNET"/> 

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


<uses-permission android:name="com.example.monitoringsensors.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<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" 

    >


    <activity
        android:name="com.example.monitoringsensors.Title"
        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="com.example.monitoringsensors.HttpExample"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.HTTPEXAMPLE" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

     <activity
        android:name="com.example.monitoringsensors.TakeSomeData"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.Dialog">
        <intent-filter>
            <action android:name="android.intent.action.TAKESOMEDATA" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>



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

</application>

</manifest>

And this is the 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"/>

And the class is called like this:

  public class HttpExample  extends android.support.v4.app.FragmentActivity {...}

Thank you mates!

Upvotes: 0

Views: 2344

Answers (2)

Smoore
Smoore

Reputation: 772

I personally use this code to check for Google Play Services, I test on both a real device running 2.3.3 and emulators on various versions of the OS, it prevents the emulators from breaking since they don't come with the updated Google Play Services that enables v2 of the Android Google Maps.
protected boolean readyToGo() {

String TAG_ERROR_DIALOG_FRAGMENT="errorDialog";

int status= GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (status == ConnectionResult.SUCCESS) {
      return(true);
    }
    else if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
      ErrorDialogFragment.newInstance(status)
                         .show(getSupportFragmentManager(),
                               TAG_ERROR_DIALOG_FRAGMENT);
    }
    else {
      Toast.makeText(this, "no maps", Toast.LENGTH_LONG).show();
      finish();
    }

    return(false);
  }

It returns true if it's able to display the map, meaning the device has the required Google Play Services, or false if it does not, which is the case for the standard emulators in Eclipse and such right now.

Upvotes: 0

Eileen Qian
Eileen Qian

Reputation: 11

you need to verify map availability Before you can interact with a GoogleMap object, you will need to confirm that an object can be instantiated, and that the Google Play services components are correctly installed on the target device. You can verify that the GoogleMap is available by calling the MapFragment.getMap() orMapView.getMap() methods and checking that the returned object is not null. https://developers.google.com/maps/documentation/android/map#verify_map_availability

Upvotes: 1

Related Questions