0

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

1 回答 1

0

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

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

希望它有所帮助。

于 2013-01-09T08:26:06.573 回答