1

Not to be confused with drawing a circle ON mapview. I'm trying to accomplish the following.

enter image description here

Should I, and how: a) create the MapView as a circular view on another View? b) render the MapView fullscreen and overlay another view with a transparent circle?

I'm not sure if either of these options are possible, I assume they are. If it helps, as part of the user workflow the opaque area will have a couple of buttons but will eventually go away and the user will be left with the full screen map to interact with.

Thanks

cagreen
  • 1,627
  • 1
  • 14
  • 29

3 Answers3

1

A workaround I've found is by manipulating CardView cornderRadius attribute and wrapping MapView inside it. Setting cardCornerRadius the half of layout_width and layout_height will create a circle View in which you can add MapView. If you don't want the shadow, set cardElevation to 0dp.

Here's the code example

<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>
Vincent Paing
  • 2,308
  • 3
  • 17
  • 29
0

You can play around with canvas .See the following link for a rounded corner MapView:-

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

Blundell
  • 75,855
  • 30
  • 208
  • 233
Krishnanunni Jeevan
  • 1,719
  • 1
  • 15
  • 24
0

Try this code

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

Dont forget to add overlay.enableMyLocation(); in onresume() and overlay.disableMyLocation(); in on pause

Instead of the above code if you want to draw circle around you point you can use following sample code:

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);
Nikhil
  • 16,194
  • 20
  • 64
  • 81