Android Maps API v2授权失败

用户名

所有与地图相关的API均已启用。当我尝试在真实设备上运行时,出现空白的Google Map屏幕。在下面的代码中,我有意删除了要发布的api密钥。

MainActivity.java

package com.example.hellomap;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MainActivity extends FragmentActivity {
    private GoogleMap mMap;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        if (mMap != null) {
            return;
        }
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        if (mMap == null) {
            return;
        }
        // Initialize map options. For example:
        // mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- TODO: Replace "com.example.hellomap" with your desired package name -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.hellomap"
          android:versionCode="1"
          android:versionName="1.0">

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15"/>

<!-- TODO: Replace "com.example.hellomap" with your package name -->
<permission
        android:name="com.example.hellomap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
<uses-permission android:name="com.example.hellomap.permission.MAPS_RECEIVE"/>

<!-- The following four permissions -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

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

<application
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher">

    <!-- TODO: Insert your Maps API key here. See this page for more information:
         https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key -->
    <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="Removed for posting"/>

    <activity
            android:name="MainActivity"
            android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

main.xml(布局)

<?xml version="1.0" encoding="utf-8"?>
<!--
See this page for more XML attribute options
https://developers.google.com/maps/documentation/android/map#using_xml_attributes
-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:map="http://schemas.android.com/apk/res-auto"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment"
          map:mapType="normal"/>
埃米尔·阿兹(Emil Adz)

如果您已将google-play-service更新revision 13,则应meta-data在清单文件中添加以下标记:

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

我建议你重新检查你已经打开Google Maps V2 API for AndroidAPI Console最后,如果所有这些都不起作用,请尝试重新生成SHA1指纹,然后在控制台中重新注册它。在缓存新API密钥之前,请不要忘记从设备中完全删除应用程序。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章