谷歌地图有效,但MapFragment没有

时间:2017-03-24 19:06:11

标签: android maps fragment supportmapfragment

我开发了一个使用MapActivity的应用程序。我在Manifest中关联了一个API-KEY,我在Gradle 10.2.0中使用谷歌播放服务...

我的问题:

在我的AVD和我的真实设备(带有Nougat的Galaxy s6,Android 7)上,我可以看到地图并正确加载。但在某些设备上它没有,我不知道为什么?当然是相同的API密钥。我正在使用supportMapFragment。

例如,在这些手机上,地图保持灰色,左下角有谷歌徽标。

enter image description here

enter image description here

enter image description here

同样在Galaxy s3 4.03和4.1.1中也不起作用。在Xiaomi Mi MAX上它起作用。

清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ibas.locatixteamviewer">

<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps"></activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:noHistory="true"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".ListActivity"
        android:label="@string/title_activity_list"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".FahrzeugActivity"
        android:label="@string/title_activity_fahrzeug"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".WebActivity"
        android:label="@string/title_activity_web"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".ListMapsActivity"
        android:label="@string/title_activity_list_maps"></activity>
</application>

activity_maps.xml

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

<!--<Button-->
    <!--android:id="@+id/button1"-->
    <!--android:layout_width="wrap_content"-->
    <!--android:layout_height="wrap_content"-->
    <!--android:background="#359c5e"-->
    <!--android:layout_alignParentTop="true"-->
    <!--android:layout_alignParentEnd="true"-->
    <!--android:padding="8dp"-->
    <!--android:layout_margin="5dp"-->
    <!--android:src="@drawable/menu_car_side_7_white"-->
    <!--android:textColor="#ffffff" />-->

</fragment>

摇篮

compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.google.android.gms:play-services-maps:10.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
testCompile 'junit:junit:4.12'

}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "ibas.locatixteamviewer"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

2 个答案:

答案 0 :(得分:0)

<application>代码

的清单顶部添加此内容
<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="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" />

答案 1 :(得分:0)

在移动设置中检查位置服务的应用权限。如果不允许,则允许位置,然后重新启动应用