因为很多重叠的Android的地图表现不佳? [英] Android Map Performance poor because of many Overlays?
问题描述
我在我的Android应用程序的地图,显示许多标记(〜20-50)。但是,应用程序执行得非常可怜,当我尝试滚动/变焦(在谷歌Android地图我做了样品寻找比萨饼和有也发现了一些20-50的结果,我没有注意到,当缩放/滚动浏览任何特别的性能问题地图)。
下面是我的(伪)code:
的onCreate(){
....
绘制= this.getResources()getDrawable(R.drawable.marker1)。
itemizedOverlay =新MyItemizedOverlay(绘制,图形页面);
...
callWebServiceToRetrieveData();
createMarkers();
}
createMarkers(){
对于(ELEM:bigList){
GeoPoint对象的GeoPoint =新的GeoPoint((INT)(elem.getLat()* 1000000),(INT)(elem.getLon()* 1000000));
OverlayItem overlayItem =新OverlayItem(的GeoPoint,elem.getName(),elem.getData());
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
}
mapView.invalidate();
}
在MyItemizedOverlay.addOverlay看起来是这样的:
公共无效addOverlay(OverlayItem叠加){
m_overlays.add(叠加);
填充();
}
如果我理解它是如何工作正常,你不应该在调用填充后,每增加一个重叠。你应该这样做,一旦你添加了他们所有。我认为发生的事情是,你添加的第一个 OverlayItem
和呼叫填充()
所以它补充说,到 ItemizedOverlay。
然后你第二次 OverlayItem
添加到列表中,并调用填充()
,并将其添加这些的两个的覆盖到 ItemizedOverlay
造成的三的在覆盖项目。所以我觉得你得到比你认为的20-50办法了。
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 for pizza and there were also some 20-50 results found and i didn't notice any particular performance problems when zooming/scrolling through the map).
Here is my (pseudo)code:
onCreate() {
....
drawable = this.getResources().getDrawable(R.drawable.marker1);
itemizedOverlay = new MyItemizedOverlay(drawable,mapView);
...
callWebServiceToRetrieveData();
createMarkers();
}
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);
mapOverlays.add(itemizedOverlay);
}
mapView.invalidate();
}
the MyItemizedOverlay.addOverlay looks like this:
public void addOverlay(OverlayItem overlay) {
m_overlays.add(overlay);
populate();
}
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.
这篇关于因为很多重叠的Android的地图表现不佳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!