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) {
}
}
}
}