android - 将 Google map 添加到 Android 应用

标签 android google-maps android-maps-v2

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

这是我的 list :

<?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" />

最佳答案

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

enter image description here

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

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

点击 File > Import,选择 Android > Existing Android Code into Workspace,然后浏览工作区导入库项目。

检查它是否是一个库项目。右击得到属性选择android。您会看到 Is Library checked 如下。

enter image description here

接下来在你的android map 项目中引用library项目

右键单击您的 android map 项目转到属性。选择安卓。单击添加浏览库项目并单击添加并应用。

enter image description here

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

关于android - 将 Google map 添加到 Android 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16395495/

相关文章:

android - 可以允许在 Android 应用程序中取消选中所有单选按钮吗?

java - 下载并安装APK

java - Android - 基于 pubnub 聊天的自定义 ListView

ios - iOS 中 gDrive SDK 集成中的重复符号问题

android - 如何在 Google Maps V2 中启用特定路线的交通信息?

google-maps-markers - 在 Android Maps V2 中,有没有办法在点击标记时控制 map 的定位?

android - Exif 数据 TAG_ORIENTATION 始终为 0

javascript - 使用 Knockout.JS 和谷歌地图 API

ios - 使用 GMSPlaceField.addressComponents 的 findPlaceLikelihoodsFromCurrentLocation 失败

Android 谷歌地图在标记上长按/在标记上触摸带有运动事件