Google地图for Android无法呈现

时间:2016-04-23 21:42:48

标签: java android google-maps

我最近将我的所有工具更新为sdk 23.当我使用活动向导创建Google Maps Activity时,它会成功创建,但是当我在设备上运行时,地图不会显示。我得到的只是左下角的谷歌徽标。

我尝试过的事情:

使用debug.keystore

中的SHA-1创建API密钥

- 重新生成的API密钥和经过验证的软件包名称

- 确保我启用了Google地图v2 for Android'而不是谷歌地图v2'

- 看了一眼并尝试了我能找到的这个网站上的所有相关解决方案(+ - 10),其中没有一个有效

- 确保我将google-play-services作为项目依赖

- 确保Google Play服务与其他工具一起更新

我的宣言:     

<!--
     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" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<permission android:name="com.venon.ranger.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.venon.ranger.permission.MAPS_RECEIVE"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">

    </activity>

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaxxxxxxxxxxxxxxxxxxxx" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver android:name=".PushReceiver">
        <intent-filter>

            <!-- Do not modify this -->
            <action android:name="pushy.me" />
        </intent-filter>
    </receiver>

    <!-- Pushy Update Receiver -->
    <!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
    <receiver android:name="me.pushy.sdk.receivers.PushyUpdateReceiver">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_REPLACED" />

            <data android:scheme="package" />
        </intent-filter>
    </receiver>

    <!-- Pushy Boot Receiver -->
    <!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
    <receiver android:name="me.pushy.sdk.receivers.PushyBootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

    <!-- Pushy Socket Service -->
    <!-- Do not modify - internal socket background service -->
    <service android:name="me.pushy.sdk.services.PushySocketService" />
</application>

我的App-Gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.venon.ranger"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:23.0.0'
   compile 'com.google.android.gms:play-services-maps:8.4.0'

}

我的MapActivity.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:apiKey = "AIzaxxxxxxxxxxxxxxxxxxxxxxxxxx"
tools:context="com.venon.ranger.MapsActivity" />

我的MapActivity.java

package com.venon.ranger;

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);



}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng disturbance = new LatLng(-34, 151);

    mMap.addMarker(new MarkerOptions().position(disturbance).title("Disturbance"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(disturbance));

}
}

我的想法很新鲜。

1 个答案:

答案 0 :(得分:1)

此问题通常与用于签署清单的Maps API Key有关。在Google API console中创建API密钥时,需要确保使用调试密钥库。

当您准备将应用推向市场时,请在AndroidManifest.xml中设置android:debuggable="false"并使用Signed API key

使用已签名的API密钥时,只有从Android电子市场安装应用程序时,MapView才会显示。因此,MapView将显示出来。

如果您的应用中有多个软件包,请在创建API密钥时注意,必须使用android mainfest.xml文件顶部的软件包名称

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

这是一个相关的堆栈溢出票据,它讨论Google地图无法渲染地图:Android and strange error with maps from google