Android Google地图在叠加层上绘制文字和图标

时间:2012-03-05 17:53:16

标签: android google-maps

当我使用叠加在谷歌地图上绘制文字/图标时,我遇到了一个问题。它只能绘制文本而不能绘制图标。但是对于文本,当我平移地图(移动地图)时,测试停留在同一个地方(实际上,在移动地图时,文本不能水平移动但可以垂直移动)。 这是我的代码:

  class myRecommendationOverlay extends Overlay
    {
        List<Restaurant> restlist = new ArrayList<Restaurant>() ;

        public void setRestlist(List<Restaurant> ls)
        {
            restlist = ls;
        }

        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)
        {
            super.draw(canvas, mapView, shadow);

            if(restlist.size() != 0)
            {      

                for(int i = 0; i < restlist.size(); i++)
                {
                    Point restaurantPoint = new Point();
                    GeoPoint tempPoint = new GeoPoint((int)(((Restaurant)restlist.get(i)).getLatitude()*1E6),(int)(((Restaurant)restlist.get(i)).getLongitude()*1E6));
                    mapView.getProjection().toPixels(tempPoint, restaurantPoint);  
                    Paint mPaint = new Paint();
                    mPaint.setStrokeWidth(1);
                    mPaint.setARGB(255, 0, 0, 0);
                    mPaint.setStyle(Paint.Style.STROKE);
                    mPaint.setTextAlign(Paint.Align.CENTER);
                    //Bitmap restIcon = BitmapFactory.decodeResource(getResources(), R.drawable.restaurant);
                    //canvas.drawBitmap(restIcon,restaurantPoint.x, restaurantPoint.y, null);
                    canvas.drawText(((Restaurant)restlist.get(i)).getName(), restaurantPoint.x , restaurantPoint.y, mPaint);
                }

            }       
            return true;
        }
    }    

谢谢大家。

0 个答案:

没有答案
相关问题