Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MapFragment API v2 empty map with just zoom controls

Im trying to implement the MapFragment and I'm running into a problem that the mapfragment is displayed but it's empty, and I just see the zoom controls.

Here's my code.

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

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

<permission
    android:name="com.example.myapp.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="com.example.myapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<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="true" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.myapp.ActivityMain"
        android:label="@string/app_name"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity><activity
    android:name=".ActivityCentres"
    android:label="@string/app_name"
    android:screenOrientation="portrait">

</activity>
    <activity
        android:name=".ActivityCentrePage"
        android:label="@string/app_name"
        android:screenOrientation="portrait">

    </activity>
    <activity
        android:name=".ActivityViewTimetable"
        android:label="@string/app_name"
        android:screenOrientation="portrait">

    </activity>
    <activity
        android:name=".ActivityOpeningTimes"
        android:label="@string/app_name">

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

</manifest>

.java

LatLng HAMBURG = new LatLng(53.558, 9.927);
LatLng KIEL = new LatLng(53.551, 9.993);
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    if (map !=null){
        Log.d("FUApp", "Map isnt 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)));
    }
    else
    {
        Log.d("FUApp", "map is null");
    }

I've got my API key by running this command

keytool -list -v -alias androiddebugkey -keystore C:/Users/Tom/.android/debug.keystore -storepass android -keypass android

and copying the SHA-1 and putting it into the google API console "MySHA1;com.example.myapp"

I've checked the Google Maps Android V2 is enabled on services.

As far as I can see I've got everything right, but it's still loading up a blank map.

like image 226
TMH Avatar asked Nov 11 '22 22:11

TMH


1 Answers

You should change your min sdk to 12 or above.

Use MapFragment for api 12 and above and use SupportMapFramgent for api 11 and below.

http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html

Looking at this

 http://developer.android.com/about/dashboards/index.html

I think it is better to change your min sdk to 12

like image 52
Raghunandan Avatar answered Nov 15 '22 00:11

Raghunandan