【问题标题】:Add Google Maps to Android app将 Google 地图添加到 Android 应用程序
【发布时间】:2013-05-06 09:13:31
【问题描述】:

我需要帮助将 Google 地图添加到我的 Android 应用。我已按照以下说明进行操作 https://developers.google.com/maps/documentation/android/start,但在运行应用程序时仍然出现错误。

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.image.app" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".map" android:label="@string/app_name"
        android:configChanges="keyboardHidden|orientation">
        <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="AIzaSyBHPmNLCVvmVSCNTWYvhMUB65f1dwqSG5Y" />
</application>
<permission android:name="com.image.app.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.image.app.permission.MAPS_RECEIVE" />
<!-- Access Internet -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Take picture -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- GET Latitude Longitude -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:glEsVersion="0x00020000"
    android:required="true" />

这是我的主要课程:

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

 public class map extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);
}
 }

这是我的 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" />

【问题讨论】:

  • 能否贴出错误或崩溃的日志猫详细信息
  • 我收到以下错误:java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader
  • 贴一些相关的代码和清单
  • @Raghunandan 请看帖子中提到的代码
  • 你有没有在你的android地图项目中引用过google play library项目?你的 api 版本是多少?

标签: android google-maps android-maps-v2


【解决方案1】:

转到窗口。安卓 SDK 管理器。向下滚动,在 extras 下选择 google play services 并安装

将 google-play services_lib 库项目复制到您的工作区。库项目可以在以下路径下找到。

     <android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib library project .

点击文件>导入,选择Android>Existing Android Code into Workspace,浏览工作区导入库项目。

检查它是否是一个库项目。右键获取属性选择android。您会看到是否已检查库,如下所示。

接下来在你的 android 地图项目中引用库项目。

右键单击您的 android 地图项目 goto 属性。选择安卓。点击添加浏览库项目并点击添加并应用。

确保您的 api 为 12 及以上。如果不是,您应该使用需要支持库的支持片段。

【讨论】:

  • 我的主要问题是我无法下载 google play 服务库
  • @meryld'souza 为什么会这样?
  • 每当我打开 SDK 管理器时,我都会收到此错误:无法获取 URL dl-ssl.google.com/android/repository/addons_list.xml,原因:连接超时:连接
  • code.google.com/p/android/issues/detail?id=41231。检查链接中的解决方案。如果没有任何效果,请重新安装 eclipse 并下载 android sdk.stackoverflow.com/questions/3808167/… 的新副本。在stackoverflow上搜索。很多类似的帖子
  • @Raghunandan 我按照您回答中的步骤操作,当我尝试运行应用程序时,它给了我以下错误消息:“无法执行 dex:GC 开销限制超出 GC 开销限制”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-31
  • 1970-01-01
相关资源
最近更新 更多