【问题标题】:How to render mapview as a circle?如何将地图视图渲染为圆形?
【发布时间】:2019-01-26 04:07:21
【问题描述】:

不要与在地图视图上绘制圆圈相混淆。我正在尝试完成以下工作。

我应该,以及如何: a) 将 MapView 创建为另一个视图上的圆形视图? b) 全屏渲染 MapView 并用透明圆圈覆盖另一个视图?

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

谢谢

【问题讨论】:

标签: android android-mapview


【解决方案1】:

我发现的一种解决方法是操纵CardViewcornderRadius 属性并将MapView 包装在其中。将 cardCornerRadius 设置为 layout_widthlayout_height 的一半将创建一个圆形 View,您可以在其中添加 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>

【讨论】:

    【解决方案2】:

    试试这个代码

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

    【讨论】:

      【解决方案3】:

      你可以玩画布。圆角 MapView 见以下链接:-

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

      【讨论】:

        猜你喜欢
        • 2013-10-04
        • 2021-05-26
        • 1970-01-01
        • 1970-01-01
        • 2011-09-14
        • 1970-01-01
        • 2023-04-01
        • 2017-11-16
        • 1970-01-01
        相关资源
        最近更新 更多