与地图上大量标记的问题 [英] Problem with large number of markers on the map

查看:144
本文介绍了与地图上大量标记的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Android应用程序已经在iPhone上存在。

在应用程序中,有已经(我算)约800标记的四组在四种不同的颜色标记绘制一个地图的活动。每个组可以打开或关闭。有关标记的信息,我有内部列表。我创建了一个mapOverlay为每个组,然后我附上了叠加到地图中。我坚信,编码部分我做了正确的。但我会附上我的code反正...

的事情是,我的Nexus One无法处理所有这些标记映射。它需要大约15秒的时间来绘制500标记。然后,当所有的画,地图不是很流畅。它是那种很难缩放和浏览周围。这是可以做到的,但经验是坏的,我想看看,如果事情可以做在那里。我知道,如果我避开字符串>双转换,我可以节省一些时间,但我怀疑这将是显著。

iPhone似乎并没有显示所有这些标记问题。它大致需要约1-2秒,以显示所有这些,缩放和平移并不坏。慢下来是明显的,但还是可以接受的。我个人认为这是没有好绘制所有这些标记,但应用程序是由别人设计的,我不应该做任何剧烈的变化。

我不知道这里做什么。看来我将不得不拿出不​​同的功能,也许还可以利用GPS定位,如果知道的话,有的半径范围内只画出标记,或者,如果位置不知道,屏幕采用中心(MAP)和周围绘制标记。我必须为我的老板的情况下,我做出这些变化合理的解释。

我AP preciate如果任何人有任何IDAS。

而code:

 名单,其中,叠加> mapOverlays =调用MapView.getOverlays();
    可绘制绘制= this.getResources()getDrawable(R.drawable.pin_blue)。
    绘制= this.getResources()getDrawable(R.drawable.pin_blue)。
    ArrList = appState.GetSleepArrList();
    ItemizedOverlay itemizedoverlay =新ItemizedOverlay(绘制,这一点);
    ...
    ...
       为(中间体米= 0; M&其中; ArrList.size();米++){
            TNAME = ArrList.get(M)获得(姓名)的toString()。
            TID = ArrList.get(M)获得(ID)的toString()。
            = TLAT ArrList.get(M)获得(土地增值税)。的toString();;
            TLNG = ArrList.get(M)获得(LNG)。的toString();;
            尝试 {
                纬度= Double.parseDouble(TLAT);
                LNG = Double.parseDouble(TLNG);
                P1 =新的GeoPoint(
                        (INT)(LAT * 1E6)
                        (中间体)(LNG * 1E6));
                OverlayItem overlayitem =新OverlayItem(P1,TNAME,TID);
                itemizedoverlay.addOverlay(overlayitem);
            }赶上(NumberFormatException异常E){
                Log.d(TAG,NumberFormatException的+ E);
            }
        }
        mapOverlays.add(itemizedoverlay);
        mapView.postInvalidate();
 

................................

 公共类ItemizedOverlay扩展ItemizedOverlay< OverlayItem>
{
    私人的ArrayList< OverlayItem> mOverlays =新的ArrayList< OverlayItem>();
    私人语境mContext;
    公共HelloItemizedOverlay(可绘制defaultMarker,上下文语境)
    {
        超(boundCenterBottom(defaultMarker));
        mContext =背景;
    }

    公共无效addOverlay(OverlayItem叠加)
    {
        mOverlays.add(叠加);
        填充();
    }
    @覆盖
    保护OverlayItem createItem中(int i)以
    {
        返回mOverlays.get(ⅰ);
    }
    @覆盖
    公众诠释大小()
    {
        返回mOverlays.size();
    }
    @覆盖
    受保护的布尔中的onTap(INT指数)
    {
        最后OverlayItem项目= mOverlays.get(指数);
                    ......每个标记将有onclick事件,将产生CLICABLE
                    ...气球带标记的名称。
        返回true;
    }
}
 

解决方案

嘛。原来,我打电话添加标记后填充()每次。我把填充()出addOverlay()方法,我循环完成后调用它。所有标记现在表明几乎瞬间。现在唯一的问题是,地图是非常不响应时,以较低的变焦(呈现出许多标记一次)。我没有看到这个解决方案,除非我想出如何降低在地图上标记的号码时图缩小。考虑到组上忙....目前正在对这个...

I am working on an Android app that already exists on iPhone.

In the app, there is a Map activity that has (I counted) around 800 markers in four groups marked by drawable in four different colors. Each group can be turned on or off. Information about markers I have inside List. I create a mapOverlay for each group, then I attach that overlay to the map. I strongly believe that coding part I did properly. But I will attach my code anyway...

The thing is, my Nexus One can't handle map with all those markers. It takes around 15 seconds just to draw 500 markers. Then when all drawn, map is not quite smooth. It is sort of hard to zoom and navigate around. It can be done, but experience is bad and I would like to see if something can be done there. I know if I avoid String > Double conversion, I could save some time, but I doubt that would be significant.

iPhone seems doesn't have problems showing all these markers. It takes roughly about 1-2 seconds to show all of them and zooming and panning is not that bad. Slow down is noticeable but still acceptable. I personally think it is no good to draw all those markers, but app is designed by somebody else and I am not supposed to make any drastic changes.

I am not sure what to do here. It seems I will have to come up with different functionality, maybe use GPS location, if known, and draw only markers within some radius, or, if location not known, use center of the screen(map) and draw markers around that. I will have to have reasonable explanation for my bosses in case I make these changes.

I appreciate if anybody has any idas.

And the code:

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.pin_blue);
    drawable = this.getResources().getDrawable(R.drawable.pin_blue);
    ArrList = appState.GetSleepArrList();
    ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable, this); 
    ...
    ...
       for (int m = 0; m < ArrList.size(); m++) {
            tName = ArrList.get(m).get("name").toString();
            tId = ArrList.get(m).get("id").toString();
            tLat = ArrList.get(m).get("lat").toString();;
            tLng = ArrList.get(m).get("lng").toString();;
            try {
                lat = Double.parseDouble(tLat);
                lng = Double.parseDouble(tLng);
                p1 = new GeoPoint(
                        (int) (lat * 1E6), 
                        (int) (lng * 1E6));
                OverlayItem overlayitem = new OverlayItem(p1, tName, tId);
                itemizedoverlay.addOverlay(overlayitem);
            } catch (NumberFormatException e) {
                Log.d(TAG, "NumberFormatException" + e);    
            }
        }
        mapOverlays.add(itemizedoverlay);
        mapView.postInvalidate();

................................

public class ItemizedOverlay extends ItemizedOverlay<OverlayItem>
{
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private Context mContext;
    public HelloItemizedOverlay(Drawable defaultMarker, Context context)
    {
        super(boundCenterBottom(defaultMarker));
        mContext = context;
    }

    public void addOverlay(OverlayItem overlay)
    {
        mOverlays.add(overlay);
        populate();
    }
    @Override
    protected OverlayItem createItem(int i)
    {
        return mOverlays.get(i);
    }
    @Override
    public int size()
    {
        return mOverlays.size();
    }
    @Override
    protected boolean onTap(int index)
    {
        final OverlayItem item = mOverlays.get(index);
                    ... EACH MARKER WILL HAVE ONCLICK EVENT THAT WILL PRODUCE CLICABLE 
                    ... BALOON WITH MARKER'S NAME.          
        return true;
    }       
}    

解决方案

Well. It turned out I call populate() every time after adding an marker. I took populate() out of addOverlay() method and I am calling it after loop finishes. All markers now show almost instantaneously. The only problem now is that the map is very unresponsive when at lower zoom (showing a lot of markers at once). I don't see solution for this unless I figure out how to decrease number of markers on the map when map is zoomed out... thinking to group them somehow.... currently working on this...

这篇关于与地图上大量标记的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆