Google Maps Android API v2 仅在我触摸屏幕时显示图块

Pab*_*blo 1 android google-maps-android-api-2

问题

当应用程序启动时,它会显示一个白色的谷歌地图(我可以看到谷歌标志),即使在互联网连接良好的情况下等待几分钟也不会加载图块。

但是,如果我触摸屏幕,瓷砖开始出现(每次触摸一个瓷砖)。

我用 3 部实体手机进行了测试,得到了相同的结果。

地图活动

public class MapActivity extends Activity {

    private MapView mMapView;
    private GoogleMap gmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);

        mMapView = (MapView) findViewById(R.id.map);
        mMapView.onCreate(savedInstanceState);
        gmap = mMapView.getMap();
        gmap.getUiSettings().setMyLocationButtonEnabled(false);
        gmap.getUiSettings().setZoomControlsEnabled(false);
        gmap.getUiSettings().setCompassEnabled(false);
        gmap.getUiSettings().setAllGesturesEnabled(false);
        gmap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

        MapsInitializer.initialize(mMapView.getContext());
    }

}
Run Code Online (Sandbox Code Playgroud)

布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:id="@+id/frameLayout">
    <com.google.android.gms.maps.MapView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

显化

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nst.lazzus" >

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

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

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.nst.lazzus.MapActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="MY_API_KEY"/>
</application>
Run Code Online (Sandbox Code Playgroud)

日志

03-01 13:37:53.627  18306-18306/com.nst.lazzus I/x? Making Creator dynamically
03-01 13:37:53.631  18306-18306/com.nst.lazzus W/ResourcesManager? Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
03-01 13:37:53.632  18306-18306/com.nst.lazzus W/ResourcesManager? Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
03-01 13:37:53.648  18306-18306/com.nst.lazzus I/Google Maps Android API? Google Play services client version: 6587000
03-01 13:37:53.656  18306-18306/com.nst.lazzus I/Google Maps Android API? Google Play services package version: 6776438
03-01 13:37:54.095  18306-18321/com.nst.lazzus W/art? Suspending all threads took: 5.532ms
03-01 13:37:54.108  18306-18321/com.nst.lazzus I/art? Background sticky concurrent mark sweep GC freed 50758(2MB) AllocSpace objects, 15(1627KB) LOS objects, 14% free, 21MB/25MB, paused 7.115ms total 52.092ms
03-01 13:37:54.222  18306-18367/com.nst.lazzus D/OpenGLRenderer? Render dirty regions requested: true
03-01 13:37:54.228  18306-18306/com.nst.lazzus D/Atlas? Validating map...
03-01 13:37:54.278  18306-18367/com.nst.lazzus I/Adreno-EGL? <qeglDrvAPI_eglInitialize:410>: QUALCOMM Build: 10/24/14, 167c270, I68fa98814b
03-01 13:37:54.279  18306-18367/com.nst.lazzus I/OpenGLRenderer? Initialized EGL, version 1.4
03-01 13:37:54.292  18306-18367/com.nst.lazzus D/OpenGLRenderer? Enabling debug mode 0
Run Code Online (Sandbox Code Playgroud)

P-a*_*röm 5

确保您MapView从以下的相应方法转发对这些方法的调用Activity

onCreate(Bundle savedInstanceState)
onDestroy()
onLowMemory()
onPause()
onResume()
onSaveInstanceState(Bundle outState)
Run Code Online (Sandbox Code Playgroud)

我可以看到您现在正在转发的唯一方法是onCreate.

但是,更方便的解决方案是使用MapFragmentor SupportMapFragment