Android Google Map不加载活动小的布局 [英] Android Google Map not loading in activity small layout

查看:297
本文介绍了Android Google Map不加载活动小的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我在底部的活动中使用地图视图,但是地图无法正常加载。点击地图2-3后,显示清晰的地图。当相同的地图如果加载在全面查看它加载明确。
这是什么解决方案?

In my application i'm using map view in activity at bottom side.but map doesn't load properly.after clicking on map 2-3 time its shows clear map.& when same map if load in full view it's loading clearly. What is the solution for this?

屏幕截图是 -

<com.google.android.gms.maps.MapView
            android:id="@+id/map"
            android:layout_width="fill_parent"
            android:layout_height="200dp"
            android:layout_margin="10dp" />

java代码 -

java code-

try {
            MapsInitializer.initialize(getApplicationContext());
        } catch (GooglePlayServicesNotAvailableException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()) )
        {
        case ConnectionResult.SUCCESS:

            mapView = (MapView)findViewById(R.id.map);
            mapView.onCreate(savedInstanceState);
            // Gets to GoogleMap from the MapView and does initialization stuff
            if(mapView!=null)
            {
                map = mapView.getMap();
                map.getUiSettings().setMyLocationButtonEnabled(false);
                map.setMyLocationEnabled(true);
                CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(locationPosition, 10);
                map.animateCamera(cameraUpdate);
                map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            }
            break;
        case ConnectionResult.SERVICE_MISSING: 

            break;
        case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: 

            break;
        default: Toast.makeText(getApplicationContext(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()), Toast.LENGTH_SHORT).show();
        }

        CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(locationPosition).zoom(10).bearing(0) // Sets the orientation of the camera to east
        .tilt(70)    // Sets the tilt of the camera to 30 degrees
        .build();    // Creates a CameraPosition from the builder
        map.setBuildingsEnabled(true);
        map.setMyLocationEnabled(true);
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        map.addMarker(new MarkerOptions() .position(locationPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marker)));


推荐答案

我有一个非常类似的问题(我坚持使用MapView即使在此时已被弃用)。
这是我的问题,也是我的答案:

I had a very similar problem(I insisted working with the MapView even though it is deprecated at this point). Here it is my issue and also my answer: Android Map loading very slow/not loading at all in started activity until clicking on it

你需要实现以下方法:
OnResume();的onPause();的onDestroy(); onLowMemory();

You need to implement the following methods: OnResume(); OnPause(); onDestroy(); onLowMemory();

希望它有帮助。

这篇关于Android Google Map不加载活动小的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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