2016-04-23 77 views
0

我最近更新了所有工具到sdk 23.當我使用活動向導創建Google Maps活動時,它創建成功,但是當我在設備上運行它時,地圖不顯示。我所得到的是左下角的谷歌徽標。Google Maps for android not rendering

我已經試過:使用

- 創建API密鑰SHA-1在debug.keystore發現

-Regenerated API密鑰和驗證軟件包名稱

訂做相信我能「谷歌地圖V2爲Android」而不是‘谷歌地圖V2’

-Looked在並試圖在本網站所有相關的解決方案,我能找到 - ,其中沒有工作

的(+ 10) 10

訂做確認自己的Google Play服務作爲項目依賴

訂做確保谷歌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-搖籃:

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

此問題通常與用於簽署清單的Maps API Key有關。在Google API console中創建API密鑰時,您需要確保使用調試密鑰庫。

當您準備將應用程序推向市場時,請在AndroidManifest.xml中設置android:debuggable="false"並使用Signed API key

使用簽名的API密鑰時,只有在Android Market安裝應用程序時,纔會顯示MapView。所以,MapView會顯示出來。

如果你在你的應用程序幾個包,當你創建你必須使用包含在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" > 

這裏的頂級包名的API密鑰提防的一個相關的堆棧溢出票哪討論谷歌地圖不提供地圖:Android and strange error with maps from google

+1

'當使用簽名的API密鑰時,只有當應用程序從Android Market安裝時,MapView纔會顯示。因此,MapView將顯示出來.'通知您可以將多個證書分配給單個api密鑰,因此您可以輕鬆地同時擁有調試和發佈證書,並且不再打擾任何更多 –