Skip to content Skip to sidebar Skip to footer

How To Overlay Glsurfaceview Over A Mapview In Android?

I want to create a simple Map based application in android ,where i can display my current position.Instead of overlaying a simple Image on the MapView to represent the position, i

Solution 1:

I was stuck on a similar problem until I looked at the documentation and realized that MapView extends ViewGroup, so overlaying a GlSurfaceView actually ends up being pretty trivial.

MapView.addView(...) and MapView.LayoutParams allow you to some pretty useful things like place a View at a specific GeoPoint on the map.

More documentation: https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/MapView.LayoutParams.html

Here's what I did:

@OverrideprotectedvoidonCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapview);

    MapViewmap_view= (MapView) findViewById(R.id.map_view);

    CustomGlViewgl_view=newCustomGlView(this);

    // This is where the action happens.
    map_view.addView(gl_view, newMapView.LayoutParams(
            MapView.LayoutParams.FILL_PARENT, 
            MapView.LayoutParams.FILL_PARENT, 
            0,0, 
            MapView.LayoutParams.TOP_LEFT
            )
        );
}

Plus also do what the solution above states. I sub-classed GlSurfaceView, so mine looks slightly different:

publicCustomGlView(Context context) {
    super(context);
    YourCustomGlRendererrenderer=newYourCustomGlRenderer();
    setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    setRenderer(renderer);
    getHolder().setFormat(PixelFormat.TRANSLUCENT);

    // Have to do this or else // GlSurfaceView wont be transparent.
    setZOrderOnTop(true);  
}

Solution 2:

You need to create the GLSurfaceView and set its EGLConfigChooser like this:

glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

then set the format of the holder to translucent

glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);

and add the GLSurfaceView and the MapView to the Layout

setContentView(glSurfaceView);

addContentView(mapView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

finally in your renderer you'll need to set the clear color so it is transparent

gl.glClearColor(0, 0, 0, 0);

Post a Comment for "How To Overlay Glsurfaceview Over A Mapview In Android?"