Android Map Performance poor because of many Overlays?

孤者浪人 提交于 2019-12-03 08:56:25

If I understand how this works correctly, you should not be calling populate after every add an overlay. You should do it once you've added them all. I think what's happening is that you add the first OverlayItem and call populate() so it adds that to the ItemizedOverlay. Then you add a second OverlayItem to the list and call populate() and it adds those two overlays to the ItemizedOverlay resulting in three items in the overlay. So I think you're getting way more than the 20-50 that you think.

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?

Jason Hocker

I ran into the same problem last night, and my solution was the same as yours. I felt weird about how I called the populate method.

I had the same code as you but I called

speedyPopulate() { 
  populate(); 
}

in the MyOverlay class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!