加入谷歌地图Android应用 [英] Add Google Maps to Android app

查看:134
本文介绍了加入谷歌地图Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助添加谷歌地图到我的Andr​​oid应用程序。我已经跟着指示
https://developers.google.com/maps/documentation/android/start ,但我仍然运行应用程序时出现错误。

这是我的清单:

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.image.app安卓版code =1机器人:=的versionName1.0>
<应用机器人:图标=@绘制/图标机器人:标签=@字符串/ APP_NAME>
    <活动机器人:地图NAME =机器人:标签=@字符串/ APP_NAME
        机器人:configChanges =keyboardHidden |方向>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>
            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
    <元数据机器人:名字=com.google.android.maps.v2.API_KEY
        机器人:值=AIzaSyBHPmNLCVvmVSCNTWYvhMUB65f1dwqSG5Y/>
< /用途>
<允许机器人:名字=com.image.app.permission.MAPS_RECEIVE
    安卓的ProtectionLevel =签名/>
<使用许可权的android:NAME =com.image.app.permission.MAPS_RECEIVE/>
<! - 接入互联网 - >
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
<使用许可权
    机器人:名字=com.google.android.providers.gsf.permission.READ_GSERVICES/>
<! - 拍摄照片 - >
<使用许可权的android:NAME =android.permission.CAMERA/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
<! - GET纬度经度 - >
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
<使用特征的android:glEsVersion =0x00020000
    机器人:要求=真/>

这是我的主类:

 进口android.app.Activity;
进口android.os.Bundle; 公共类地图扩展活动{
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.map);
}
 }

这是我的XML:

 <?XML版本=1.0编码=UTF-8&GT?;
<片段的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID /图的an​​droid:layout_width =match_parent
机器人:layout_height =match_parent机器人:名字=com.google.android.gms.maps.MapFragment/>


解决方案

转到窗口。 Android SDK中的经理。向下滚动选择谷歌发挥服务群众演员下安装

在谷歌播放services_lib库项目复制到您的工作空间。库项目可以在以下路径下找到。

 < Android的SDK文件夹> /演员/谷歌/ google_play_services / libproject /谷歌播放services_lib库项目。

点击文件>导入,选择的Andr​​oid>现有Android的code到工作区,浏览该工作区导入库项目。

要检查它的库项目。右键得到属性中进行选择机器人。你看到的是库查如下图所示。

接下来参照库项目在你的Andr​​oid地图的项目。

右键点击你的Andr​​oid地图项目转到属性。选择机器人。单击添加浏览库项目,然后单击添加和应用。

请确保您的API为12以上。如果你不应该使用它需要支持库支持片段。

I need help adding Google Maps to my Android app. I have followed the instructions on https://developers.google.com/maps/documentation/android/start, but I still get an error when running the app.

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 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. Scroll down choose google play services under extras and install

Copy the google-play services_lib library project to your workspace. 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.

To check if its a library project. Right click got properties choose android. You see Is Library checked as below.

Next refer the library project in your android map project.

Right click on your android map project goto properties. choose android. click add browse the library project and click add and apply.

Make sure your api is 12 and above. If not you should use support fragment which requires support library.

这篇关于加入谷歌地图Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆