谷歌地图“标记变焦时移动变焦、标记、地图

由网友(穷追一个梦)分享简介:我添加了一个标记,以我的地图,但是当我放大它移动到左侧(最大放大它标志着正确的地方),当我缩小它移动到右侧(最大放大了它的标记像3000公里从正确的地方)。I've added a mark to my map but when I zoom in it moves to the left (at maximum z...

我添加了一个标记,以我的地图,但是当我放大它移动到左侧(最大放大它标志着正确的地方),当我缩小它移动到右侧(最大放大了它的标记像3000公里从正确的地方)。

I've added a mark to my map but when I zoom in it moves to the left (at maximum zoom in it marks the right place) and when I zoom out it moves to the right (at maximum zoom out it marks like 3000Km from the right place).

下面是绘制标记物的onCreate之前(图像62px宽x 70像素高)类:

Here's the class that draws the marker before the onCreate (the image is 62px w x 70px h):

class MapOverlay extends com.google.android.maps.Overlay
    {
        @Override
        public boolean draw(Canvas canvas, MapView map, boolean shadow, long when) 
        {
            super.draw(canvas, map, shadow);                   

            Point screenPts = new Point();
            map.getProjection().toPixels(point, screenPts);

            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mapmarker);            
            canvas.drawBitmap(bmp, screenPts.x + 50, screenPts.y - 70, null);         
            return true;
        }
    } 

和这里的code我用它来调用类:

And here's the code I use to call the class:

        latitud = loc.getLatitude();
            longitud = loc.getLongitude();
            precision = loc.getAccuracy();

        controlMapa = map.getController();
        point = new GeoPoint((int) (latitud * 1E6), (int) (longitud * 1E6));

        controlMapa.animateTo(point);
        controlMapa.setZoom(17);

        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = map.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);

        map.invalidate();

这是什么问题?我怎样才能让它们移动到正确的点每次变焦的变化?

What's the problem? How can I make them move to the correct point each time zoom changes?

感谢你在前进!

推荐答案

解决了!我不得不补充:

Solved! I just had to add:

canvas.drawBitmap(bmp, screenPts.x - (bmp.getWidth() / 2), screenPts.y - bmp.getHeight(), new Paint());

而不是:

canvas.drawBitmap(bmp, screenPts.x + 50, screenPts.y - 70, null); 
阅读全文

相关推荐

最新文章