2010-05-13 42 views
3

我想在android中創建一個簡單的基於地圖的應用程序,在那裏我可以顯示我的當前位置。替代覆蓋MapView上的簡單圖像來表示位置,我想覆蓋MapView上的GLSurfaceView。但我不知道如何實現這一點。有沒有辦法做到這一點?請有人知道該解決方案可以幫助我。如何在Android中通過MapView覆蓋GLSurfaceView?

+0

嗨Rajapandian,你有沒有找到你的文章的解決方案?因爲,現在我處於相同的情況。你能幫我麼 ? – 2014-02-24 08:30:23

回答

3

您需要創建GLSurfaceView並設置其EGLConfigChooser這樣的:

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

然後將支架的格式半透明

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

,並添加GLSurfaceView和MapView到佈局

setContentView(glSurfaceView);

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

終於在你的渲染器,你需要設置明確的顏色,所以它是透明的

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

+0

我應用了這種方法,但旋轉不適用。 Mapview保持穩定。 – 2011-01-18 15:51:39

4

我被困在一個類似的問題,直到我看了看文檔和意識到MapView延伸ViewGroup,所以覆蓋GlSurfaceView實際上最終是相當微不足道的。

MapView.addView(...)MapView.LayoutParams允許你一些非常有用的東西,比如將View放置在地圖上的特定GeoPoint上。

更多的文檔:https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/MapView.LayoutParams.html

這裏就是我所做的:

@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還做上述國家的解決方案。我分類GlSurfaceView,所以我看起來略有不同:

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