在我的Google地图中心创建十字线 [英] Creating a Crosshair in the Center of My Google Map

查看:108
本文介绍了在我的Google地图中心创建十字线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android开发新手,我遇到了一个问题,我一直在努力工作数小时而没有成功。我想在我的Google地图的中心创建一个十字线,即使在地图平移时,它仍停留在中心位置。我的可绘制目录中有一个十字线的.png图像。另外,我有一个MapView,它显示带有多个标记的Google Map。什么是最好的方法来解决这个问题?

I am new to Android development and I have a problem that I have been working on for hours with no success. I want to create a cross-hair in the center of my Google Map that stays in the center even when the map is panned. I have a .png image of the cross-hair in my drawable directory. Additionally, I have a MapView that displays the Google Map with several markers. What is the best way to approach this problem?

推荐答案

public class CrossHairsOverlay extends Overlay {
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
        super.draw(canvas, mapView, shadow);
        GeoPoint centerGp = mapView.getMapCenter();
        Projection projection = mapView.getProjection();
        Point centerPoint = projection.toPixels(centerGp, null);
        Paint p = new Paint();
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.crosshairs_dial);
        canvas.drawBitmap(bmp, centerPoint.x, centerPoint.y, p);
        return true;
    }
}

这篇关于在我的Google地图中心创建十字线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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