0

Hi I am trying create circle shape on map. For that i am using ground overlay item. I tried draw circle shape with drawable xml file. First I tried in normal activity layout and it shows me perfect circle shape. same thing I tried to draw on map it looks like oval shape. My code for drawable and layout is as follows :

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

   <solid 
       android:color="#666666"/>

   <size 
       android:width="120dp"
    android:height="120dp"/>
</shape>

and my layout file :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <RelativeLayout 
    android:id="@+id/circleLay"
    android:layout_height="100dp"
    android:layout_width="100dp"
    android:layout_centerInParent="true"
    android:background="@drawable/circle">
    </RelativeLayout>

</RelativeLayout>

I tried to create ground overlay item as follows :

LatLng NEWARK = new LatLng(0, 0);
        View markerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_marker_layout, null);
        GroundOverlayOptions newarkMap = new GroundOverlayOptions()
                .image(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(this, markerView)))
                .position(NEWARK, 860000f, 650000f);
GroundOverlay imageOverlay = googleMap.addGroundOverlay(newarkMap);

same thing I tried for activity which shows me circle but for map it showing oval shape not circle shape. How to do this? Need Help. Thank you.

nilkash
  • 7,396
  • 30
  • 96
  • 170

1 Answers1

0

You could simply add a Circle directly, instead of using a GroundOverlay:

Circle circle = googleMap.addCircle(new CircleOptions()
     .center(new LatLng(40.740234,-74.171505))
     .radius(10000)
     .strokeColor(Color.GRAY)
     .fillColor(Color.GRAY));
banderkat
  • 481
  • 2
  • 6
  • 1
    I don't want to just add circle. that circle contains some other fields also like some image and text. So that why I tried with ground layout. Is there any way to add images and text in circle ? – nilkash Dec 27 '13 at 06:07
  • I see in the [Ground Overlay Options](https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/GroundOverlayOptions#position%28com.google.android.gms.maps.model.LatLng,%20float%29) that the `.position` should be specified with location and width arguments only (no height) in order to preserve proportions. – banderkat Dec 27 '13 at 06:22
  • Yeah So what I am doing I using createBitFromview in my code which it takes view and return drawable. That drawable I am using as image for my ground overlay. – nilkash Dec 27 '13 at 06:40
  • I think what you need to do is instead of this: `.position(NEWARK, 860000f, 650000f);` try this: `.position(NEWARK, 860000f);` – banderkat Dec 27 '13 at 06:54