3

I have a serious problem in implementing a Google Maps fragment into my android app. Basically, I followed all the instructions on Google's website. After obtaining a Google Maps API v2 key, setting up the layout and manifest, import the google-play-service library and initiating a GoogleMap using google's sample codes, I found out that the emulator didn't support Google Maps API v2, so I went online and download the newest version of com.android.vending.apk and com.google.android.gms.apk and then installed them into my emulator using adb install (same situation as in here: This app won't run unless you update Google Play Services (via Bazaar)). After installing them, I was finally able to implement an interface of a MapFragment.

But when I ran it in my Android emulator (OS 4.1.2; API 16), nothing in the map worked. An error saying "Failed to find provider info for com.google.android.gsf.gservices" kept coming out. I'm not sure if it has something to do with the wireless provider. Does anyone know why did it kept coming out? Any suggestion will be greatly appreciated!

To explain some of the earlier questions: the map showed up correctly. But the buttons on the map ("+" and "-") didn't work at all. Nor could I click or drag the map. Whenever I clicked any button, draged or double-clicked on the map, it gave me no response but error messages in the LogCat saying "Failed to find provider info for com.google.android.gsf.gservices".

Here is my code in AndroidManifest.xml:

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

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="17" />

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

    <uses-permission android:name="com.example.trackmyexercise.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" />
    <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.trackmyexercise.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.maps.v2.API_KEY"
            android:value="AIzaSyANkR-VPI4zy5IpYGK2Z0T1omLq3C46rFE" />
    </application>

</manifest>

Here is my layout code:

    <?xml version="1.0" encoding="utf-8"?>
<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/recordsButton"
        android:layout_alignParentTop="true" />

</RelativeLayout>

And here is my MainActivity code:

    package com.example.trackmyexercise;

import android.os.Bundle;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.view.Menu;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

public class MainActivity extends Activity {
    GoogleMap myMap;
    MapFragment myMapFragment;

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

        myMapFragment = MapFragment.newInstance();
        FragmentTransaction fragmentTransaction = getFragmentManager()
                .beginTransaction();
        fragmentTransaction.add(R.id.map, myMapFragment);
        fragmentTransaction.commit();

        myMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();
        this.setUpMapIfNeeded();
        myMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    private void setUpMapIfNeeded() {
        if (myMap == null) {
            myMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();
        if (myMap != null) {
        }
    }
    }
}
Community
  • 1
  • 1
Jerry Dex
  • 39
  • 1
  • 1
  • 4
  • So the problem is that the buttons don't work? the map is shown correctly? – Emil Adz Apr 04 '13 at 22:41
  • Nice detailed question, but we're not sure what isn't working – StackExchange User Apr 04 '13 at 22:49
  • The map itself is not working. Basically it's just a piece of picture and none of the buttons on it works neither. – Jerry Dex Apr 05 '13 at 17:56
  • I did as you all here pointed out but when I run my app in emulator, logcat spit this error as the title of this post says. I also run the google's mapdemo, put my api key and it runs perfectly in my device emulator in Eclipse Indigo. The code of my project is very similar to Lars's one. I set this for Android Api 18 also the emulator (not Google api). My android app is based on this [tutorial](http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html), it's simple but I don't see where the error is. – JoeCoolman May 12 '14 at 06:49
  • My mistake again, I put in my api google's permisons the Eclipse debug keystore, now everything goes perfect! ;-) – JoeCoolman May 14 '14 at 04:40

2 Answers2

4

Error lies here --> android:name="com.example.tackmyexercise.permission.MAPS_RECEIVE"

Your package name is incorrect here, i suppose.

It should be "com.example.trackmyexercise.permission.MAPS_RECEIVE"

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
sachinsharma
  • 195
  • 1
  • 12
1

I followed the same tutorial, had the same problem as you, and managed to get a working Map by doing the following:

  • Right-click Project
  • Select 'Project Properties'
  • Select 'Android' on the left menu
  • Under 'Project Build Target' make sure you have 'Android X.X' selected (I'm using 4.2.2), NOT the Google APIs
  • Also make sure your Android Virtual Device has 'Android X.X' as a Target Version, NOT the Google APIs

Worked for me, hope it helps you!

Jojanzing
  • 311
  • 2
  • 10