Android 将谷歌地图添加到我的应用程序
我正在尝试将谷歌地图添加到我的android应用程序中,我遵循了以下文档: 首先,我的清单文件正确吗 Manifest.xmlAndroid 将谷歌地图添加到我的应用程序,android,Android,我正在尝试将谷歌地图添加到我的android应用程序中,我遵循了以下文档: 首先,我的清单文件正确吗 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
<?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>
这是我的布局:
<?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>
如果我删除片段
标记,它可以正常工作,但一旦我将其添加回应用程序中,就会关闭并显示:“很遗憾,MainActivity已停止。”
有人看到哪里出了问题吗?也许您正在尝试在未运行Android 3.0+的设备上使用
MapFragment
MapFragment
用于活动和API级别11的本机片段实现SupportMapFragment
与Android支持库提供的FragmentActivity
和FragmentBackport一起使用
更新
经进一步审查,问题可能有两个方面:
您试图将googleplayservices.jar
附加到您的项目,而不是
通过直接修改构建路径,而不是将JAR复制到libs/
,您完成了上述第1步
撤消您最初所做的操作。然后,(作为一个副作用,它将为您正确地设置那个罐子)
因为看起来您正在进行命令行构建,所以您需要为Android库项目创建命令行构建文件,Google选择不发布该项目(grrrrrrrrrrr)。运行:
创建必要的文件。检查logcat是否有错误。原因:android.app.Fragment$InstantiationException:无法实例化Fragment com.google.android.gms.maps.MapFragment:确保类名存在,是公共的,并且有一个空构造函数是公共的
和
,原因是:java.lang.ClassNotFoundException:com.google.android.gms.maps.MapFragment您还没有在清单中声明您的类,也请检查这个。。。我正在使用三星GS3进行测试。好的。你确实把mapsv2android库项目添加到了你的项目中,对吗?@ryannady:不,那是一个JAR。它不是一个Android库项目。Google Play Services的Android库项目包含一个JAR,但您不能直接将JAR添加到项目中。现在,我可以使用“调试”构建库了/home/ryan/android sdk linux/tools/ant/build.xml:595:无效文件:/home/ryan/android sdk linux/extras/google/google\u play\u services/libproject/google-play-services\u lib/build.xml构建失败(总时间:0秒)错误现已消失,但我仍然得到:原因:java.lang.ClassNotFoundException:com.google.android.gms.maps.SupportMapFragment
android update project -p /home/ryan/android-sdk-linux/extras/google/google_play_services/libproject/google-play-services_lib