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

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

问题描述

我有问题越来越地图中我的地图片段显示。我已经尝试了几种不同的解决方案,但在地图仍为空白(灰色)。有人可以请指出我在做什么错了?我使用的SHA1指纹是一个我发现的安卓>建立的。

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上的谷歌地图控制台?是你的包名在控制台是否正确?你百分之百确定?如果有疑问,重新调试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

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

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