2012-05-16 52 views
1

不要与在地图上绘制圆圈混淆。我正在努力完成以下内容。如何将mapview渲染为圆形?

enter image description here

我应该,以及如何: 一)创建的MapView作为另一个View圆形的看法? b)使用透明圆来渲染MapView全屏并覆盖另一个视图?

我不确定这些选项是否可行,我猜想他们是。如果有帮助,作为用户工作流程的一部分,不透明区域将有几个按钮,但最终会消失,用户将留下全屏幕地图进行交互。

感谢

+0

检查这有助于:http://stackoverflow.com/q/7559171/1321873 – Rajesh

+1

http://blog.blundell-apps.com/rounded-corners-mapview / – Akram

回答

0

试试这个代码

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mapView = (MapView) findViewById(R.id.mapview); 
    MapController mc = mapView.getController(); 
    MyLocationOverlay myLocationOverlay = new MyLocationOverlay(MainMap.this, mapView); 
    mapView.getOverlays().add(myLocationOverlay); 
    mc.animateTo(new GeoPoint(lat, lng)); 
    mc.setZoom(15); 
    mapView.invalidate(); 
} 

不要忘记添加overlay.enableMyLocation();在onresume()和overlay.disableMyLocation();在暂停

,而不是上面的代码,如果你想在你身边点你可以使用下面的示例代码绘制圆:

Point screenPnts =new Point(); 
GeoPoint curr_geopoint = new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6)); 
mapview.getProjection().toPixels(curr_geopoint, screenPnts); 
canvas.drawCircle(screenPnts.x, screenPnts.y, 15, paint); 
1

我找到了一个解决方法是通过操纵CardView cornderRadius属性和包装的MapView在里面。设置cardCornerRadius的一半l ayout_widthlayout_height将创建一个圆形视图,您可以在其中添加MapView。如果你不想要阴影,请将cardElevation设置为0dp。

下面的代码示例

<android.support.v7.widget.CardView 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    app:cardCornerRadius="100dp"> 

    <com.google.android.gms.maps.MapView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    </android.support.v7.widget.CardView>