【问题标题】:Blank GoogleMap on a real Android 2.3 device真正的 Android 2.3 设备上的空白 GoogleMap
【发布时间】:2013-12-14 12:56:13
【问题描述】:

我正在尝试在 android 2.3 上显示谷歌地图。 我按照here的步骤进行操作

我正在使用 android studio 0.3.7 我得到一个类似于this的图像

MainActivity.java:

package com.Greek.Market;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

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"
tools:context=".MainActivity" >

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

清单:

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

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

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

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

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

        <activity
            android:name="com.Greek.Market.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>


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

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

</manifest>

build.grandle:

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 10
        targetSdkVersion 19
    }
    buildTypes {
        release {
            runProguard false
            proguardFile getDefaultProguardFile('proguard-android.txt')
        }
    }
    productFlavors {
        defaultFlavor {
            proguardFile 'proguard-rules.txt'
        }
    }
}

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

我直接在安卓设备上部署我的应用

根据我的阅读,我认为问题出在 api_key,但我不知道在哪里......

我通过以下命令获得 SHA1: c:\Program Files\Java\jdk1.6.0_21\bin>keytool -list -v -keystore "c:\Users\user\ .android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

有人可以帮助我吗?我被卡住了

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    几件事:

    1. 从 XML 布局文件中删除这一行:

    android:name="com.google.android.gms.maps.SupportMapFragment"
    

    2. 从你代码的其他部分我没有看到有什么问题,所以你可以做的事情可能很少:

    • 使用API Console 复制您的密钥,您可以关注此博文并确保您做的每一件事都正确:Google Maps API V2 Key,确保您打开正确的两次API for Android
    • 如果您执行了所有这些操作,但仍然遇到此问题,请确保在重新安装之前从手机中完整删除应用程序,因为 API 密钥会被缓存,直到您删除应用程序。

    【讨论】:

    • 终于成功了!!!问题是api_key。我创建了一个新的,从手机中删除了我的应用程序,它工作了!!!非常感谢
    猜你喜欢
    • 1970-01-01
    • 2018-04-23
    • 2015-08-14
    • 1970-01-01
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    相关资源
    最近更新 更多