Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 views
in Technique[技术] by (71.8m points)

opengl es - 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 want to overlay the GLSurfaceView on the MapView. But i don't know how to achieve this. Is there any way to do that?. Please anybody knows the solution help me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapview);

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

    CustomGlView gl_view = new CustomGlView(this);

    // This is where the action happens.
    map_view.addView(gl_view, new MapView.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:

public CustomGlView(Context context) {
    super(context);
    YourCustomGlRenderer renderer = new YourCustomGlRenderer();
    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);  
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...