谷歌地图Android API v2仅在我触摸屏幕时显示分幅

谷歌地图Android API v2仅在我触摸屏幕时显示分幅,android,google-maps-android-api-2,Android,Google Maps Android Api 2,问题 当应用程序启动时,它会显示一个白色的谷歌地图(我可以看到谷歌的徽标),即使在互联网连接良好的情况下等待几分钟,它也不会加载磁贴 但是,如果我触摸屏幕,瓷砖开始出现(每次触摸一块瓷砖) 我用3部物理手机进行了测试,得到了相同的结果 MapActivity public class MapActivity extends Activity { private MapView mMapView; private GoogleMap gmap; @Override

问题

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

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

我用3部物理手机进行了测试,得到了相同的结果

MapActivity

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());
    }

}
布局

<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>
<?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>

Manifiest

<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>
<?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>

日志

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
03-01 13:37:53.627 18306-18306/com.nst.lazzus I/x﹕ 动态生成创建者
03-01 13:37:53.631 18306-18306/com.nst.lazzus W/ResourcesManager﹕ 资产路径“/system/framework/com.android.media.remotedisplay.jar”不存在或不包含任何资源。
03-01 13:37:53.632 18306-18306/com.nst.lazzus W/ResourcesManager﹕ 资产路径“/system/framework/com.android.location.provider.jar”不存在或不包含任何资源。
03-01 13:37:53.648 18306-18306/com.nst.lazzus I/谷歌地图Android API﹕ 谷歌游戏服务客户端版本:6587000
03-01 13:37:53.656 18306-18306/com.nst.lazzus I/谷歌地图Android API﹕ Google Play服务包版本:6776438
03-01 13:37:54.095 18306-18321/com.nst.lazzus W/art﹕ 暂停所有线程所需时间:5.532ms
03-01 13:37:54.108 18306-18321/com.nst.lazzus I/art﹕ 背景粘性并发标记扫描GC释放50758(2MB)AllocSpace对象,15(1627KB)LOS对象,14%空闲,21MB/25MB,暂停7.115ms,总计52.092ms
03-01 13:37:54.222 18306-18367/com.nst.lazzus D/opengl﹕ 请求渲染脏区域:true
03-01 13:37:54.228 18306-18306/com.nst.lazzus D/Atlas﹕ 正在验证映射。。。
03-01 13:37:54.278 18306-18367/com.nst.lazzus I/Adreno EGL﹕ : 高通公司制造:2014年10月24日,167c270,I68fa98814b
03-01 13:37:54.279 18306-18367/com.nst.lazzus I/opengl﹕ 已初始化EGL,版本1.4
03-01 13:37:54.292 18306-18367/com.nst.lazzus D/opengl﹕ 正在启用调试模式0

getMap()
方法已被弃用。改用
getmapsync(OnMapReadyCallback)
。回调方法为您提供了一个保证为非null且可随时使用的GoogleMap实例。

getMap()
方法已被弃用。改用
getmapsync(OnMapReadyCallback)
。回调方法为您提供一个保证为非空且随时可用的GoogleMap实例。

有时GoogleMaps在绘图时会遇到问题。尝试通过添加覆盖视图来修改布局——这解决了我类似的问题

<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"/>
    <View
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</FrameLayout>

有时谷歌地图在绘图方面有问题。尝试通过添加覆盖视图来修改布局——这解决了我类似的问题

<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"/>
    <View
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</FrameLayout>

确保从
活动的相应方法向
地图视图上的这些方法转发调用:

onCreate(Bundle savedInstanceState)
onDestroy()
onLowMemory()
onPause()
onResume()
onSaveInstanceState(Bundle outState)
我看到您现在正在转发的唯一方法是
onCreate


但是,更方便的解决方案是使用
MapFragment
SupportMapFragment
确保从
活动的相应方法在
MapView
上转发对这些方法的调用:

onCreate(Bundle savedInstanceState)
onDestroy()
onLowMemory()
onPause()
onResume()
onSaveInstanceState(Bundle outState)
我看到您现在正在转发的唯一方法是
onCreate


然而,一个更方便的解决方案是使用
MapFragment
SupportMapFragment
MapView
对于
Google Maps Android API v1
,对于
Google Maps Android API v2
,您应该使用
MapFragment
。但是,您仍然可以在
Map API V2
中使用
MapView
,但需要:

此类的用户必须将所有活动生命周期方法(例如onCreate()、onDestroy()、onResume()和onPause())转发到MapView类中的相应方法

此外,调用
mMapView.onResume()
mMapView.onCreate(savedInstanceState)之后使地图快速显示

最后,您必须通过以下方式在
onCreate(…)
中初始化映射:

MapsInitializer.initialize(this);

MapView
是针对
Google地图Android API v1
,对于
Google地图Android API v2
,您应该使用
MapFragment
。但是,您仍然可以在
Map API V2
中使用
MapView
,但需要:

此类的用户必须将所有活动生命周期方法(例如onCreate()、onDestroy()、onResume()和onPause())转发到MapView类中的相应方法

此外,调用
mMapView.onResume()
mMapView.onCreate(savedInstanceState)之后使地图快速显示

最后,您必须通过以下方式在
onCreate(…)
中初始化映射:

MapsInitializer.initialize(this);

使用我做过的框架布局…试试这个


xml代码
使用我已经完成的框架布局…试试这个


xml代码


与getMapAsync(OnMapReadyCallback)的行为相同。与getMapAsync(OnMapReadyCallback)的行为相同。它也不起作用。我还尝试用线性布局替换框架布局。它也不起作用。我还尝试用线性布局替换FrameLayout。您是否应该使用片段android:name=“com.google.android.gms.maps.SupportMapFragment”
?请在应用程序上签名。并使用签名的apk进行测试。您是否应该使用
片段android:name=“com.google.android.gms.maps.SupportMapFragment”
?请在应用程序上签名。并使用签名的apk来测试为什么这是修复方法?@Jessedgans必须在MapView上调用生命周期方法才能正常工作。但是如上所述,有更好更方便的方法。为什么这是修复方法?@Jessedgans必须在MapView上调用生命周期方法才能正常工作。但如前所述,有一个