谷歌地图“标记变焦时移动 [英] Google Maps' marker moves when zooming

查看:152
本文介绍了谷歌地图“标记变焦时移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个标记,以我的地图,但是当我放大它移动到左侧(最大放大它标志着正确的地方),当我缩小它移动到右侧(最大放大了它的标记像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); 

这篇关于谷歌地图“标记变焦时移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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