I am trying to add google maps to my android application, and I followed this documentation: https://developers.google.com/maps/documentation/android/start
First off, is my Manifest file correct?
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="where.is.the.action"
android:versionCode="1"
android:versionName="1.0">
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="where.is.the.action.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="where.is.the.action.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"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="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="xxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
</application>
</manifest>
Then here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="My Location"
android:onClick="getLocation"
android:layout_weight="0"
/>
<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.MapFragment"/>
</LinearLayout>
It works fine if I remove the fragment tag, but once I add it back in the app closes and displays: “Unfortunately, MainActivity has stopped.”
Does anyone see what is wrong?
Perhaps you are trying to use
MapFragmenton a device that is not running Android 3.0+.MapFragmentis for use with anActivityand the native fragment implementation from API Level 11.SupportMapFragmentis for use with aFragmentActivityand the fragment backport supplied by the Android Support Library.UPDATE
Upon further review, the problem is probably two-fold:
You attempted to attach
google-play-services.jarto your project, instead of following the instructions and attaching the Play Services Android library project to your project.You did #1 above by messing with your build path directly, instead of copying the JAR to
libs/.Undo what you did originally. Then, follow the instructions to attach the Android library project to your project (which, as a side effect, will properly set up that JAR for you).
Since it appears that you are doing a command-line build, you will need to create the command-line build files for the Android library project, which Google elected not to ship (grrrrrrrrrrrrrrr). Run:
to create the necessary files.