简体   繁体   English

将Google地图添加到Android应用

[英]Add Google Maps to Android app

I need help adding Google Maps to my Android app. 我需要帮助将Google地图添加到我的Android应用中。 I have followed the instructions on https://developers.google.com/maps/documentation/android/start , but I still get an error when running the app. 我已按照https://developers.google.com/maps/documentation/android/start上的说明操作,但在运行应用时仍出现错误。

This my manifest: 这是我的清单:

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

This is my main class: 这是我的主要课程:

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

This is my xml: 这是我的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" />

Go to windows. 去窗户。 Android sdk manager. Android sdk经理。 Scroll down choose google play services under extras and install 向下滚动选择额外的谷歌播放服务并安装

在此输入图像描述

Copy the google-play services_lib library project to your workspace. 将google-play services_lib库项目复制到您的工作区。 The library project can be found under the following path. 可以在以下路径下找到库项目。

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

Click File > Import, select Android > Existing Android Code into Workspace, and browse the workspace import the library project. 单击文件>导入,选择Android>现有Android代码到工作区,然后浏览工作区导入库项目。

To check if its a library project. 检查它是否是一个库项目。 Right click got properties choose android. 右键单击获取属性选择android。 You see Is Library checked as below. 您会看到Is Library如下所示。

在此输入图像描述

Next refer the library project in your android map project. 接下来参考android map项目中的库项目。

Right click on your android map project goto properties. 右键单击你的android地图项目转到属性。 choose android. 选择android。 click add browse the library project and click add and apply. 单击“添加”浏览库项目,然后单击“添加并应用”。

在此输入图像描述

Make sure your api is 12 and above. 确保你的api是12及以上。 If not you should use support fragment which requires support library. 如果不是,您应该使用需要支持库的支持片段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM