Android Map Performance poor because of many Overlays?

后端 未结 3 2163
感动是毒
感动是毒 2021-02-10 03:13

I have a map in my android application that shows many markers (~20-50). But the app performs very poor when i try to scroll/zoom (in Google Android Maps i did a sample search f

3条回答
  •  盖世英雄少女心
    2021-02-10 03:52

    I've done the following now and it works fast(er):

    createMarkers(){
        for(elem:bigList){
            GeoPoint geoPoint = new GeoPoint((int)(elem.getLat()*1000000), (int) (elem.getLon()*1000000));
            OverlayItem overlayItem = new OverlayItem(geoPoint, elem.getName(), elem.getData());
            itemizedOverlay.addOverlay(overlayItem);
    
       }
       itemizedOverlay.populateNow();
       mapOverlays.add(itemizedOverlay); //outside of for loop
    

    }

    and in MyOverlay:

    public void addOverlay(OverlayItem overlay) {
        m_overlays.add(overlay);
    }
    
    public void populateNow(){
        populate();
    }
    

    is this better/correct now ? or any other improvements possible?

提交回复
热议问题