在Android上使用教程谷歌地图问题 [英] Issues with Google Maps on Android Tutorial

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

问题描述

嗨我一直在试图效仿谷歌已经对在Android中使用谷歌地图它的开发者网站上的教程。不用说,我无法得到的东西的工作,它有多个错误。所以,我切换到一从Youtube而这给我的错误了。所有我想要做的就是使地图上来。我不能做的这些错误是贴在下面。我真的希望你们可以给我一个线索怎么办。任何帮助深表AP preciated。

也有人指出,每次我面对我GOOGLE了它,并试图多的问题的时间修复。因此,在code任何不一致是由所带来的。

错误:


  

摇篮:执行失败的任务:GoogleMapsDemoV2:compileDebug


  
  

    

编译失败;详情请参见编译器错误输出。


  
  
  

C:\\Users\\Josebz\\AndroidStudioProjects\\GoogleMapsDemoV2Project\\GoogleMapsDemoV2\\src\\main\\java\\com\\example\\googlemapsdemov2\\MainActivity.java


反正这里是我所有的code ...

主要活动

 包com.example.googlemapsdemov2;进口android.support.v7.app.ActionBarActivity;
进口android.support.v7.app.ActionBar;
进口android.support.v4.app.Fragment;
进口android.os.Bundle;
进口android.view.LayoutInflater;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.view.ViewGroup;
进口android.os.Build;公共类MainActivity扩展ActionBarActivity {    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);        如果(savedInstanceState == NULL){
            getSupportFragmentManager()调用BeginTransaction()
                    。新增(R.id.container,新PlaceholderFragment())
                    。承诺();
        }
    }
    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        //处理动作栏项目点击这里。操作栏会
        //自动处理上点击主页/向上按钮,只要
        //你在AndroidManifest.xml中指定一个父活动。
        开关(item.getItemId()){
            案例R.id.action_settings:
                返回true;
        }
        返回super.onOptionsItemSelected(项目);
    }    / **
     *包含一个简单视图中的占位符片段。
     * /
    公共静态类PlaceholderFragment扩展片段{        公共PlaceholderFragment(){
        }        @覆盖
        公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
                捆绑savedInstanceState){
            查看rootView = inflater.inflate(R.layout.fragment_main,集装箱,FALSE);
            返回rootView;
        }
    }}

Android清单

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.googlemapsdemov2
    安卓版code =1
    机器人:=的versionName1.0>    <用途-SDK
        安卓的minSdkVersion =14
        机器人:targetSdkVersion =19/>    <许可
        机器人:名字=com.example.googlemapsdemov2.permission.MAPS_RECEIVE
        安卓的ProtectionLevel =签名/>
    <使用许可权的android:NAME =com.example.googlemapsdemov2.permission.MAPS_RECEIVE/>    <使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
    <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
    <使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
    <! - 不需要下面的两个权限使用
         谷歌地图Android版API V2,但建议。 - >
    <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>    <用途特征
        机器人:glEsVersion =0x00020000
        机器人:要求=真/>
    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>        &所述;元数据
            机器人:名字=com.google.android.maps.v2.API_KEY
            机器人:值=AIzaSyAL5Xq8scMIHnWXITSOLN9QipVkri4A-LI/>        <活动
            机器人:名字=com.example.googlemapsdemov2.MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>< /清单>

activity_main.xml中

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    工具:上下文=MainActivity。>
    <的TextView
        机器人:ID =@ + ID /头
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=@字符串/参考hello world/><片段
机器人:ID =@ + ID /图
机器人:名字=com.google.android.gms.maps.MapFragment
机器人:layout_below =@ + ID /头
机器人:layout_width =match_parent
机器人:layout_height =match_parent
    />
< / RelativeLayout的>

的build.gradle

  buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径'com.android.tools.build:gradle:0.6.+
    }
}
应用插件:'机器人'库{
    mavenCentral()
}安卓{
    compileSdkVersion 19
    buildToolsVersion19.0.0    defaultConfig {
        14的minSdkVersion
        targetSdkVersion 19
    }
}依赖{
    编译com.android.support:appcompat-v7:+
    编译com.android.support:support-v13:13.0.+
    编译com.google.android.gms:播放服务:3.2.25
}


解决方案

首先尝试使用下的清单文件的应用程序部分下述..

 <元数据
 机器人:名字=com.google.android.gms.version
 机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>

有关例如:您的清单文件。

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.googlemapsdemov2
    安卓版code =1
    机器人:=的versionName1.0>    <用途-SDK
        安卓的minSdkVersion =14
        机器人:targetSdkVersion =19/>    <许可
        机器人:名字=com.example.googlemapsdemov2.permission.MAPS_RECEIVE
        安卓的ProtectionLevel =签名/>
    <使用许可权的android:NAME =com.example.googlemapsdemov2.permission.MAPS_RECEIVE/>    <使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
    <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
    <使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
    <! - 不需要下面的两个权限使用
         谷歌地图Android版API V2,但建议。 - >
    <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>    <用途特征
        机器人:glEsVersion =0x00020000
        机器人:要求=真/>
    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>        &所述;元数据
        机器人:名字=com.google.android.gms.version
        机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>
       <! - 你的谷歌API密钥 - >
        &所述;元数据
            机器人:名字=com.google.android.maps.v2.API_KEY
            机器人:值=AIzaSyAL5Xq8scMIHnWXITSOLN9QipVkri4A-LI/>        <活动
            机器人:名字=com.example.googlemapsdemov2.MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>< /清单>

其次,如果你是在较低的Andr​​oid版本的测试相同,那么你需要使用SupportMapFragment的一样。尝试这样的..

 <片段
机器人:ID =@ + ID /图
机器人:名字=com.google.android.gms.maps.SupportMapFragment
机器人:layout_below =@ + ID /头
机器人:layout_width =match_parent
机器人:layout_height =match_parent
    />

希望它排序您的问题,让我知道如果任何关注。

Hey guys I've been trying to follow the tutorial that Google has on it's developers site on using Google Maps in Android. Needless to say I couldn't get the thing working and it had multiple errors. So I switched over to one from Youtube and that's giving me errors too. All I want to do is make the map come up. The errors that I couldn't work with is posted below. I really hope you guys can give me a clue as to what to do. Any help is much appreciated.

Also people note that every time I faced an issue I googled it and tried multiple 'fixes'. So any inconsistency in the code is brought about by that.

Errors:

Gradle: Execution failed for task ':GoogleMapsDemoV2:compileDebug'.

Compilation failed; see the compiler error output for details.

C:\Users\Josebz\AndroidStudioProjects\GoogleMapsDemoV2Project\GoogleMapsDemoV2\src\main\java\com\example\googlemapsdemov2\MainActivity.java

Anyway here's all my code...

Main Activity

package com.example.googlemapsdemov2;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {
            case R.id.action_settings:
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

Android Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemapsdemov2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <permission
        android:name="com.example.googlemapsdemov2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.googlemapsdemov2.permission.MAPS_RECEIVE"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <!-- The following two permissions are not required to use
         Google Maps Android API v2, but are recommended. -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAL5Xq8scMIHnWXITSOLN9QipVkri4A-lI"/>

        <activity
            android:name="com.example.googlemapsdemov2.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>
    </application>

</manifest>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


    <TextView
        android:id="@+id/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_below="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
    />
</RelativeLayout>

build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.android.support:support-v13:13.0.+'
    compile 'com.google.android.gms:play-services:3.2.25'
}

解决方案

Firstly try using undermentioned under application section of manifest file ..

<meta-data
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />

For Ex: Your manifest file ..

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemapsdemov2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <permission
        android:name="com.example.googlemapsdemov2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.googlemapsdemov2.permission.MAPS_RECEIVE"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <!-- The following two permissions are not required to use
         Google Maps Android API v2, but are recommended. -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
       <!--Your Google API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAL5Xq8scMIHnWXITSOLN9QipVkri4A-lI"/>

        <activity
            android:name="com.example.googlemapsdemov2.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>
    </application>

</manifest>

Secondly if you are testing same on lower versions of android then you need to use SupportMapFragment for same. Try like this ..

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
    />

Hope it sorts your problem and let me know if any concern ..

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

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