谷歌地图Android的API第2版样品code不工作 [英] Google Map Android Api V2 Sample Code not working

查看:143
本文介绍了谷歌地图Android的API第2版样品code不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾试图通过使用所有可用的选项,使用提供了前,其中谷歌地图样本code Google_Play_SERVICE /样品,它表明了以下日志。

I had tried to use the Google Map Sample Code before which was provided in Google_Play_SERVICE/SAMPLE by using all the available options and it showed the below Log.

01-14 17:58:39.773:E /谷歌地图Android的API(13114):授权   失败的。

01-14 17:58:39.773: E/Google Maps Android API(13114): Authorization failure.

这表明我的黑屏所有的样本地图选项。

It showed me the blank screen for all of the sample Map options.

现在,我创建了一个新的项目,这里是其完整的code: -

Now I created a new Project and here is its complete code:-

Activity.java

public class MapActivity extends FragmentActivity
{
    private Context context = this;

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

        GoogleMap gMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

        int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
        Log.e("Maps", "Result int value::" + result);
        switch (result) {
        case ConnectionResult.SUCCESS:
            Log.e("Maps", "RESULT:: SUCCESS");          
            break;

        case ConnectionResult.DEVELOPER_ERROR:
            Log.e("Maps", "RESULT:: DE");           
            break;

        case ConnectionResult.INTERNAL_ERROR:
            Log.e("Maps", "RESULT:: IE");           
            break;

        case ConnectionResult.INVALID_ACCOUNT:
            Log.e("Maps", "RESULT:: IA");           
            break;

        case ConnectionResult.NETWORK_ERROR:
            Log.e("Maps", "RESULT:: NE");           
            break;

        case ConnectionResult.RESOLUTION_REQUIRED:
            Log.e("Maps", "RESULT:: RR");           
            break;

        case ConnectionResult.SERVICE_DISABLED:
            Log.e("Maps", "RESULT:: SD");           
            break;

        case ConnectionResult.SERVICE_INVALID:
            Log.e("Maps", "RESULT:: SI");           
            break;

        case ConnectionResult.SERVICE_MISSING:
            Log.e("Maps", "RESULT:: SM");           
            break;
        case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
            Log.e("Maps", "RESULT:: SVUR");         
            break;
        case ConnectionResult.SIGN_IN_REQUIRED:
            Log.e("Maps", "RESULT:: SIR");          
            break;      

        default:
            break;
        }
        gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        gMap.setMyLocationEnabled(true);
        Log.e("Maps", "------EOC-------");
    }
}

* activity_map.xml *

*activity_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"
  class="com.google.android.gms.maps.SupportMapFragment"/>

的Manifest.xml

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

    <uses-sdk
        android:maxSdkVersion="17"
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

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

    <permission
        android:name="net.dottech.map.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="net.dottech.map.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="net.dottech.map.MapActivity"
            android:label="@string/app_name" >
            <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="removed" />
    </application>

</manifest>

LOG

01-21 13:09:09.243: E/Maps(449): Result int value::0
01-21 13:09:09.243: E/Maps(449): RESULT:: SUCCESS
01-21 13:09:09.243: E/Maps(449): ------EOC-------
01-21 13:09:09.248: D/LocationManagerService(1852): gps location requested by an application
01-21 13:09:09.253: D/SensorManager(449): registerListener :: handle = 0  name= K3DH 
Acceleration Sensor delay= 20000 Listener= maps.i.a@41a054f8
01-21 13:09:09.353: D/(449): Device driver API match
01-21 13:09:09.353: D/(449): Device driver API version: 10
01-21 13:09:09.353: D/(449): User space API version: 10 
01-21 13:09:09.353: D/(449): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Fri May  4 10:32:42 KST 2012
01-21 13:09:12.398: D/Sensors(449): Remain listener = Sending .. normal delay 200ms
01-21 13:09:12.398: I/Sensors(449): sendDelay --- 200000000
01-21 13:09:12.398: I/Sensors(1852): setDelay :: handle = 0   delay = 200000000
01-21 13:09:12.398: D/SensorManager(449): JNI - sendDelay
01-21 16:14:17.835: E/Google Maps Android API(12168): Failed to load map.  Could not contact Google servers.

截图

这是结果,缩放选项,在图形页面没有地图空白屏幕。

我按照每一步中提到: -

I have followed each and every step mentioned at:-

1)。教程

2。)谷歌地图Android的API第2

推荐答案

请检查..

  1. 检查是否存在于你的项目中包含了Android的支持 - v4.jar的库文件夹中。

  1. check if the "libs" folder containing the "android-support-v4.jar" exists in your project.

Android的支持 - v4.jar位于/extras/android/compatibility/v4/android-support-v4.jar在你的Android的SDKdrectory。

"android-support-v4.jar" is located in "/extras/android/compatibility/v4/android-support-v4.jar" under your "android-sdk" drectory.

运行项目之前,必须设置你的项目构建的目标,以谷歌API的,而不是Android的XX版本:选择你的项目,然后单击在Eclipse项目>属性>项目构建目标,并选择任何谷歌API的,然后在手机上运行您的项目。如果使用模拟器,还必须设置仿真器连接到任何谷歌的API的AVD。

Before running your project, you must set your project Build target to "Google APIs", not Android x.x. version : Select your project and click Project > Properties > Project Build Target in Eclipse and select any "Google APIs ", and then run your project on your phone. If you use the emulator, also MUST set the AVD of the emulator to the any "Google APIs ".

再次,你不需要为了创建新的谷歌地图API密钥,以测试你的项目,只要使用默认提供的API密钥,表示为键浏览器的应用程序(与查阅情况) 在你的谷歌API控制台。

Once more, you don't need to create the new Google Maps API key in order to test your project, Just use the default provided API key, which is shown as "Key for browser apps (with referers) "in your Google APIs Console.

最后,最重要的是加入谷歌Play业务作为一个Android库项目如下:

Finally, the most important is to add Google Play services as an Android library project as follows:

选择文件>导入> Android的>现有的Andr​​oid code进入工作区,然后单击下一步。 选择浏览...,输入/演员/谷歌/ google_play_services / libproject /谷歌播放services_lib,然后单击Finish。

Select File > Import > Android > Existing Android Code Into Workspace and click Next. Select Browse..., enter /extras/google/google_play_services/libproject/google-play-services_lib, and click Finish.

这篇关于谷歌地图Android的API第2版样品code不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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