Question

I have read numerous questions on this matter, but none of them seem to fix my problem. The zoom tiles are appearing but the map isn't loading up. I am running the app on an android device so it can't be an issue with the emulator. I have created an API key and also added the google play library into the project. Below shows all code created so it would be very helpful if someone could point me in the right direction.

AndroidManifest.xml

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

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

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



<permission
  android:name="package.name.permission.MAPS_RECEIVE"
  android:protectionLevel="signature"/>
<uses-permission android:name="package.name.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"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-library android:name="com.google.android.maps" />
    <activity
        android:name="com.example.androidgooglemap.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>
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="KEY"/>
</application>

Activity_Main.xml

<?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"
      android:name="com.google.android.gms.maps.MapFragment"/>

MainActivity.java

package com.example.androidgooglemap;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

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

}

Was it helpful?

Solution

You have to change the package in the following permissions in the Manifest file:

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

To your package, so you have to change those to this:

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

And of course as already suggested change MapFragment to SupportMapFragment because you are supporting low version devices.

OTHER TIPS

in your map fragment use

android:name="com.google.android.gms.maps.SupportMapFragment"

because you have a low api support:

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top