How to properly use drawMyLocation

后端 未结 1 1482
执笔经年
执笔经年 2021-01-16 20:12

I am trying to show the users current location with the default blue dot in android. In my maps page I also have a layout that shows different points of interest. Im having

相关标签:
1条回答
  • 2021-01-16 20:14

    try this way in your map activity

    class CurOverlay extends Overlay {
            private GeoPoint pointToDraw;
    
            public void setPointToDraw(GeoPoint point) {
                pointToDraw = point;
            }
    
            public GeoPoint getPointToDraw() {
                return pointToDraw;
            }
    
            @Override
            public boolean draw(Canvas canvas, MapView curmapView, boolean shadow,
                    long when) {
                super.draw(canvas, curmapView, shadow);
    
                // convert point to pixels
                Point screenPts = new Point();
                curmapView.getProjection().toPixels(pointToDraw, screenPts);
    
                // add marker
                Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                        R.drawable.pinsource);
                canvas.drawBitmap(bmp, screenPts.x - 28, screenPts.y - 48, null);
                return true;
            }
    
        }
    

    i hope this will work for you.

    0 讨论(0)
提交回复
热议问题