【问题标题】:Performance issue in Android MapViewAndroid MapView 中的性能问题
【发布时间】:2012-06-26 09:01:28
【问题描述】:

我正在开发自定义地图应用程序,我可以在其中从网络服务获取数据并根据该数据显示叠加项目。这是我运行我的应用程序时的问题,它会正确显示地图和叠加层,但是当我尝试缩放它或尝试点击它时,它变得很慢,性能非常慢。所以这里提出了一些性能问题。事实上,它不包含大量数据,只有 50 个叠加层。

我怀疑添加项目覆盖有问题,请检查并帮助我。

代码:

private void showWhaleDophinSightingsToMap() {
    mapOverlays = mapView.getOverlays();
    progressDialog.dismiss();
    // Show overlay for whale sightings
    Log.i(TAG, "whaleWatchingInfoList >>>>>> " + whaleWatchingInfoList);
    Log.i(TAG, "whaleWatchingInfoList >>>>>> "+ whaleWatchingInfoList.size());
    if(whaleWatchingInfoList != null && whaleWatchingInfoList.size() > 0) {
            drawable = getResources().getDrawable(R.drawable.north);            
            customItemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
            for(int i = 0; i < whaleWatchingInfoList.size(); i++) {
                    if(i == 0) {
                            MapController mc = mapView.getController();
                            mc.setZoom(7);
                            // Zoom Level 
                            mapView.getController().setCenter(new GeoPoint((int)(whaleWatchingInfoList.get(i).getLatitude() * 1E6),
                            (int)(whaleWatchingInfoList.get(i).getLongtitude() * 1E6)));
                    }else {
                            geoPoint = new GeoPoint((int)(whaleWatchingInfoList.get(i).getLatitude() * 1E6),
                            (int)(whaleWatchingInfoList.get(i).getLongtitude() * 1E6));
                            CustomOverlayItem customOverlayItem = new CustomOverlayItem(geoPoint, whaleWatchingInfoList.get(i).getName(), whaleWatchingInfoList.get(i).getDescription(), whaleWatchingInfoList.get(i).getImageUrl(), whaleWatchingInfoList.get(i).getAtdwProductUrl());
                            customItemizedOverlay.addOverlay(customOverlayItem);    
                            mapOverlays.add(customItemizedOverlay);
                    }
            }
    }
    mapView.postInvalidate();   
}

【问题讨论】:

    标签: android android-mapview android-maps


    【解决方案1】:

    我不确定能否回答。在我的情况下,我在获取地图视图时添加了 2 行,它在地图移动或缩放时提高了很多性能。它解决了我的问题。

    mapView.setAlwaysDrawnWithCacheEnabled(true);
    mapView.setPersistentDrawingCache(MapView.PERSISTENT_ALL_CACHES);
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多