Android的 - 在我的谷歌地图的中心创建一个十字我的、创建一个、地图、中心

2023-09-06 06:01:11 作者:无爱者自拥

我是新的Andr​​oid开发,我有,我已经工作了几个小时,但没有成功的一个问题。我想创建一个跨头发在我的谷歌地图的中心是停留在即使在地图平移中心。我在我的绘制目录中的十字线的的PNG图片。另外,我有一个显示与几个标志物的谷歌地图一个图形页面。什么是解决这个问题的最好方法是什么?

任何帮助是极大的AP preciated。

感谢您,

TUONG

解决方案

 公共类CrossHairsOverlay扩展覆盖{
    公共布尔平局(画布油画,图形页面图形页面,布尔影子,时长){
        super.draw(帆布,图形页面,阴影);
        的GeoPoint centerGp = mapView.getMapCenter();
        投影投影= MapView.getProjection()在;
        点中心点= projection.toPixels(centerGp,NULL);
        涂料P =新的油漆();
        BMP位= BitmapFactory.de codeResource(getResources(),R.drawable.crosshairs_dial);
        canvas.drawBitmap(BMP,centerPoint.x,centerPoint.y,P);
        返回true;
    }
}
 

谷歌开始在Android用户中测试Google Maps交通信号灯功能

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?

Any help is greatly appreciated.

Thank you,

Tuong

解决方案

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;
    }
}

 
精彩推荐
图片推荐