【问题标题】:Google map showing gray tiles only on android studio谷歌地图仅在 android studio 上显示灰色瓷砖
【发布时间】:2017-09-20 06:39:37
【问题描述】:

我创建了一个带有谷歌地图活动的新安卓项目。我的活动代码是:

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 sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

}

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>

<!--
     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.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="xxxxxx.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permisson.READ_GSERVICES"/>

<uses-permission android:name="xxxxx.mapservice.permission.MAPS_RECIEVE"/>
<uses-permission android:name="xxxxx.provides.gsf.permission.READ_GSERVICES"/>
<permission android:name="xxxxx.mapservice.permission.MAPS_RECIEVE"
    android:protectionLevel="signature"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    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">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

我得到了一个 google Api 密钥并使用 sh1 密钥对其进行限制。我关注了谷歌文档,但不幸的是我的地图没有加载。

虽然我正在搜索一些建议我应该删除 debug.keystore 的 cmets,但这对我不起作用。我错过了什么?

另外我的地图布局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="ir.iuwa.testmap.MapsActivity" />

【问题讨论】:

    标签: android api google-maps dictionary key


    【解决方案1】:

    将此添加到应用程序标记之外的清单中并检查

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

    【讨论】:

      【解决方案2】:

      我找到了解决方案! 我的错误在于生成正确的 sha1 代码。以前,我使用以下过程在 android studio 右侧使用 gradle 菜单找到了此密钥:首先单击 gradle,然后在 app、Tasks、android 下,单击signingReport:

      然后 sha1 出现在 gradle 控制台中:

      我的错误是这段代码是用于调试模式的! 我按照以下过程为我的发布密钥库获取 sha1 版本,在谷歌开发者控制台中输入这个新的 sha1 后,我的地图完全出现。 要获得 sha1 版本,首先您应该复制您的发布密钥库地址: 转到构建 >> generateSigendApk 并复制您的密钥存储路径。

      那么您应该复制android studio 使用的jdk 的路径。转到文件>> ProjectStructure,您可以看到您的jdk路径。复制此路径并在 cmd 中转到此文件夹。

      然后 cd yor jdk 然后 bin 文件夹并复制以下行: keytool -list -v -keystore "您复制的密钥存储路径" -alias "KEY ALIAS" 现在输入并享受您的发布 sha1 代码:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-27
        • 2013-08-01
        • 2013-06-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-08
        • 1970-01-01
        相关资源
        最近更新 更多