谷歌地图片段显示空白的灰色地图

时间:2014-05-30 09:00:45

标签: android google-maps android-fragments android-maps-v2

我在地图片段中显示地图时遇到问题。我尝试了几种不同的解决方案,但地图仍为空白(灰色)。有人可以指出我做错了什么吗?我正在使用的SHA1指纹是我在 Android>中找到的指纹。构建

注意:如果它显示“来自开发者控制台的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>

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:0)

更改硬盘后我遇到了同样的问题。

我在谷歌控制台上创建新的Api密钥,新的SHA1后解决了我的问题。