Skip to content Skip to sidebar Skip to footer

Draw Over Google Map V2 Android

I created an android app to draw free shapes over 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 a

Solution 1:

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.

Then by following code you can change that x,y points into latitude and longitude.

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.

map.setOnCameraChangeListener(new OnCameraChangeListener() {

    @Override
    publicvoidonCameraChange(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 coordNow draw line between thistwo (x,y) points.
    }


});

Hope I can make you clear and you can understand what I want to say.

Post a Comment for "Draw Over Google Map V2 Android"