【问题标题】:Android Google Map not loading in activity small layoutAndroid Google Map 未在活动小布局中加载
【发布时间】:2014-04-04 08:44:07
【问题描述】:

在我的应用程序中,我在底部的活动中使用地图视图。但地图无法正确加载。点击地图 2-3 次后,它会显示清晰的地图。& 当相同的地图以全视图加载时,它正在加载清楚地。 解决办法是什么?

屏幕截图是-

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

java代码-

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上显示方框。它在地图上点击2-3次后加载地图
  • 发布你的所有代码 ppplzz
  • 或者您可以在 mMapView.onResume();pause mMapView.onPause(); 上恢复 mapview
  • 我没有得到你。我在活动中使用这个

标签: android google-maps map android-activity android-mapview


【解决方案1】:

我遇到了一个非常相似的问题(我坚持使用 MapView,尽管此时它已被弃用)。 这是我的问题,也是我的答案:Android Map loading very slow/not loading at all in started activity until clicking on it

您需要实现以下方法: OnResume();暂停(); onDestroy(); onLowMemory();

希望对你有帮助。

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
猜你喜欢
  • 2011-07-16
  • 1970-01-01
  • 1970-01-01
  • 2021-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多