谷歌地图应用程序 - 无法成功创建一个简单的地图应用程序

时间:2013-11-23 12:59:43

标签: android

在尝试设置我的谷歌地图应用示例时,我似乎遇到了谷歌连接授权方面的一些问题,它向我展示了一个带缩放选项但没有+或 - 的灰色屏幕,这里是logcat:

11-23 16:01:46.811: E/Google Maps Android API(19391): Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
11-23 16:01:46.821: E/Google Maps Android API(19391): Ensure that the following correspond to what is in the API Console: Package Name: com.example.zpot3, API Key: AIzaSyA6Z5FOsq1XD-9Ui6HHZ7FN0pH8sX3cwUI, Certificate Fingerprint: ED6E2DCAC367F47AB12DC92559E5C148CE8376BB
11-23 16:01:46.831: I/Google Maps Android API(19391): Failed to contact Google servers. Another attempt will be made when connectivity is established.
11-23 16:01:51.396: D/memalloc(19391): /dev/pmem: Unmapping buffer base:0x4bc42000 size:19845120 offset:18493440
11-23 16:01:51.396: D/memalloc(19391): /dev/pmem: Unmapping buffer base:0x4e6c2000 size:6021120 offset:4669440
11-23 16:01:51.406: D/memalloc(19391): /dev/pmem: Unmapping buffer base:0x4ec80000 size:12103680 offset:10752000
11-23 16:01:57.232: I/Adreno200-EGLSUB(19391): <ConfigWindowMatch:2089>: Format RGBX_8888.
11-23 16:01:57.242: D/memalloc(19391): /dev/pmem: Mapped buffer base:0x4bc42000 size:6021120 offset:4669440 fd:96
11-23 16:01:57.312: D/memalloc(19391): /dev/pmem: Mapped buffer base:0x4c34a000 size:13455360 offset:12103680 fd:105
11-23 16:01:57.382: D/memalloc(19391): /dev/pmem: Unmapping buffer base:0x4bc42000 size:6021120 offset:4669440
11-23 16:01:57.382: D/memalloc(19391): /dev/pmem: Unmapping buffer base:0x4c34a000 size:13455360 offset:12103680
11-23 16:02:02.016: E/Google Maps Android API(19391): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
11-23 16:02:06.010: I/Adreno200-EGLSUB(19391): <ConfigWindowMatch:2089>: Format RGBX_8888.
11-23 16:02:06.020: D/memalloc(19391): /dev/pmem: Mapped buffer base:0x4bc42000 size:13578240 offset:12226560 fd:96
11-23 16:02:06.080: D/memalloc(19391): /dev/pmem: Mapped buffer base:0x4ca7f000 size:6021120 offset:4669440 fd:105

2 个答案:

答案 0 :(得分:0)

请参阅此处,只需使用清单文件中的密钥更改api密钥,然后按照以下步骤操作: 并且确保使用android清单文件中提到的包名称生成api密钥,并且google_play_services_lib项目应仅存在于项目的工作空间中。

清单文件:              

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

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

    <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" />
    <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="com.geeklabs.map.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>

        <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="replace with your API key"/>

    </application>

</manifest>

MainActivity.java:

    package com.geeklabs.map;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

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

}

activity_main.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"/>

得到这个后告诉我。

答案 1 :(得分:0)

确保以下步骤正确无误:

步骤: *确保该设备具有Google Play服务APK *安装Google Play服务版。超过2

enter image description here

  • https://code.google.com/apis/console/
  • 创建项目
  • 启用“Google Maps Android API v2” enter image description here
  • 在API控制台注册项目中的SHA1(现在,你需要写SHA1;你的.app.package.name )并获取API KEY
  • 将目录ANDROID_SDK_DIR / extras / google / google_play_services / libproject / google-play-services_lib复制到项目的根目录
  • 将下一行添加到YOUR_PROJECT / project.properties

android.library.reference.1=google-play-services_lib

  • 将下一行添加到YOUR_PROJECT / proguard-project.txt

-keep class * extends java.util.ListResourceBundle {

protected Object[][] getContents();

}

好的,现在您已准备好使用适用于Android的Google Map API V2创建自己的Google地图应用。

如果使用min SDK = 8创建应用程序,请使用android支持库v4 + SupportMapFragment而不是MapFragment。