Android中的空白谷歌地图MapView

时间:2016-07-10 19:24:08

标签: android google-maps

我目前的问题是,无论我到目前为止做什么,我的应用程序中的MapView始终是空白的。我得到了SH:IA密钥和包名,生成了我的代码,并将其放在" google_maps_key.xml" " debug / res / values"中的文件文件夹和"发布/ res /值"文件夹,这就是结果:

Layout

清单:



<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="com.flashitdelivery.flash_it_partner">
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.GET_ACCOUNTS"
    tools:remove="android:maxSdkVersion" />

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

<application android:allowBackup="true" android:name=".activity.MyApplication" android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
    <activity android:name=".activity.SplashActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".activity.MainActivity" android:theme="@style/AppTheme"></activity>
    <!--Auth0 Lock-->
    <activity android:name="com.auth0.lock.LockActivity" android:theme="@style/Lock.Theme"
        android:screenOrientation="portrait" android:launchMode="singleTask">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="a0iYoER9BjZdrjeOhRmwov6o3ppirgsETj"
                android:host="flashit.auth0.com" />
        </intent-filter>
    </activity>
    <meta-data android:name="com.auth0.lock.client-id" android:value="@string/auth0_client_id" />
    <meta-data android:name="com.auth0.lock.domain-url" android:value="@string/auth0_domain" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

    <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" />
    <!--Auth0 Lock End-->
</application>
&#13;
&#13;
&#13;

依赖关系:

&#13;
&#13;
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.auth0.android:lock:1.14.+'
    compile 'com.google.android.gms:play-services-gcm:9.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.google.firebase:firebase-core:9.2.0'
    compile 'com.google.firebase:firebase-messaging:9.2.0'
    compile 'com.google.android.gms:play-services:9.2.0'
}

apply plugin: 'com.google.gms.google-services'
&#13;
&#13;
&#13;

布局:

&#13;
&#13;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:name="com.google.android.gms.maps.SupportMapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:background="@color/flashItPartner_purple"
        android:id="@+id/driverUpperIcons">

    </RelativeLayout>

    <com.google.android.gms.maps.MapView
        android:layout_width="match_parent"
        android:layout_height="225dp"
        android:layout_below="@+id/driverUpperIcons"
        android:apiKey="@string/google_maps_key"
        android:id="@+id/googleMapObject"></com.google.android.gms.maps.MapView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/googleMapObject"></LinearLayout>



</RelativeLayout>
&#13;
&#13;
&#13;

我不知道如何解决这个问题。我希望有人能指引我朝正确的方向发展。

4 个答案:

答案 0 :(得分:0)

我通常使用此版本的地图片段:

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

 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.SupportMapFragment" />

此外,请务必确保您拥有互联网权限,将google play服务添加到build.gradle文件中,然后它就可以正常使用了!

答案 1 :(得分:0)

检查官方文档。这是非常好的解释!

链接:Maps Android API for Android

答案 2 :(得分:0)

您可以尝试将您的Api密钥添加到Manifest标记中的Application

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

然后使用Fragment,如:

<fragment
    android:name="com.google.android.gms.maps.SupportMapFragment"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

答案 3 :(得分:0)

确保您在项目构建的API控制台中使用相同的SHA1指纹,生成SHA-1 key,使用它来获取API密钥并将其放入元数据中清单文件。

如果您enabled Google Maps Android API检查了您的logcat,请检查开发者控制台,可能会有一些关于Google地图的错误日志。

您可以查看此演示应用,了解如何使用Google Maps API:https://github.com/googlemaps/android-samples

有关如何解决问题的详细信息,请查看此处的官方文档,按照如何创建包含地图活动的应用项目的步骤进行操作:https://developers.google.com/maps/documentation/android-api/start

相关问题