显示空白灰色地图的 Google 地图片段 [英] Google Maps fragment showing blank grey map

查看:35
本文介绍了显示空白灰色地图的 Google 地图片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在我的地图片段中显示地图.我尝试了几种不同的解决方案,但地图仍然空白(灰色).有人可以指出我做错了什么吗?我使用的 SHA1 指纹是我在 Android > Build 中找到的指纹.

I'm having problems with getting the map in my map fragment to show. I have tried several different solutions but the map remains blank (grey). Can somebody please point out what I'm doing wrong? The SHA1 fingerprint I'm using is the one I found in Android > Build.

注意:上面写着来自开发者控制台的 api 密钥",我当然已经输入了正确的密钥.

Fragment01.java

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.LatLng;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Fragment01 extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_01, container, false);
// Gets the MapView from the XML layout and creates it
mapView = (MapView) v.findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);

// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
MapsInitializer.initialize(this.getActivity());
// Updates the location and zoom of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
map.animateCamera(cameraUpdate);
return v;
}
}

Fragment01.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.gms.maps.MapView android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

</LinearLayout>

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="se.sebastianliljegren.nellienovafoto"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<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"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>
    <permission
android:name="se.sebastianliljegren.nellienova.foto.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
        <uses-permission    android:name="se.sebastianliljegren.nellienovafoto.permission.MAPS_RECEIVE"/>
<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
    <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api key from developers console"/>
    <uses-library
android:name="com.google.android.maps"
android:required="true" /> 
    <activity
        android:name="se.sebastianliljegren.nellienovafoto.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>

推荐答案

如果您得到一张灰色地图,则是与服务器的通信问题.重新检查您的 api 密钥,您是否在谷歌地图控制台中为 ANDROID 激活了谷歌地图?您在控制台中的包名称是否正确?你100%确定吗?如果有疑问,请重新创建调试 apikey 或发布.此外,如果地图是灰色的,则必须有一些日志,请检查您的 logcat 是否有来自 api 的警告

If you are getting a grey map it's a communication issue with the servers. Recheck your api key, did you activate google map in the google map console for ANDROID ? is your package name correct in the console ? Are you 100% sure ? If there is doubt ReCreate a debug apikey or release. Also if the map is grey there must be some log, check your logcat for warnings from the api

这篇关于显示空白灰色地图的 Google 地图片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆