简体   繁体   English

在Google Map V2 Android上绘制

[英]Draw over google map v2 android

I created an android app to draw free shapes over google map v2. 我创建了一个Android应用来在Google Map v2上绘制自由形状。 The idea of the app is that I combines two apps, one is to draw free shapes and the other is normal google map v2 app. 该应用程序的想法是,我将两个应用程序结合在一起,一个是绘制自由形状,另一个是普通的google map v2应用程序。

This link is my last question about this app and it contains the code 链接是我关于此应用的最后一个问题,其中包含代码

The app works well with me but now I have a new problem. 该应用程序对我来说效果很好,但是现在我遇到了一个新问题。 My problem is that when I draw a line over a specific location on the map and convert control to map and drag it, I found that the line keep in its place in the view and the map moves under the line and this leads the line to be in another location not the location that I want. 我的问题是,当我在地图上的特定位置绘制一条线并将其转换为地图并将其转换为拖动控件时,我发现该线在视图中保持原位,并且地图在该线下方移动,这导致该线到达在另一个位置而不是我想要的位置。

Is there are any way to make the line to be steady in the location I draw in it and when I drag the map the line dragged with its location? 有什么方法可以使线条在我绘制的位置稳定,当我拖动地图时,拖动的线条及其位置如何?

Hope anyone got my mean. 希望有人明白我的意思。

For example if you are drawing line on your mapview using canvas then you need to get x,y points of start and end point. 例如,如果要使用画布在地图视图上绘制线,则需要获取起点和终点的x,y点。

Then by following code you can change that x,y points into latitude and longitude. 然后,通过以下代码,您可以将x,y指向经度和纬度。

public boolean onTouchEvent(MotionEvent event)
{
    int X = (int)event.getX();          
    int Y = (int)event.getY();

    GeoPoint geoPoint = mapView.getProjection().fromPixels(X, Y);
}

Then resgister listener on your mapvierw like this. 然后像这样在mapvierw上重新设置监听器。

map.setOnCameraChangeListener(new OnCameraChangeListener() {

    @Override
    public void onCameraChange(CameraPosition arg0) {
        // Move camera.
     Here remove your view from screen and then get lat long of visible region by       passing x,y points of 4 regions in `mapView.getProjection().fromPixels(x,y)` and then check if latitude and longitude of your line within range if yes then drawline by following code.

     float pisteX;
     float pisteY;
     Projection projection = this.mapView.getProjection(); 
     Point pt = new Point();
     GeoPoint gie = new GeoPoint(latitude,longitude);
     Rect rec = mapView.getScreenRect(new Rect());
     projection.toPixels(gie, pt);
     pisteX = pt.x-rec.left; // car X screen coord
     pisteY = pt.y-rec.top; // car Y screen coord

     Now draw line between this two (x,y) points.
    }


});

Hope I can make you clear and you can understand what I want to say. 希望我能使你清楚,你能理解我想说的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM