4

Instead of having a polygon with a solid line surrounding it I want to create one with a dotted line, is this possible?

I know you could do this when you override the onDraw method of the overlay in v1 but the Overlay class does not exist anymore so how else can I achieve this?

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • http://stackoverflow.com/q/6098947/2110460 currently says no – Rafe Mar 13 '13 at 20:58
  • @Rafe thats the javascript API not android – tyczj Mar 13 '13 at 21:00
  • I am guessing https://developers.google.com/maps/documentation/javascript/overlays#PolylineSymbols would not help either then? It seems that first link was a little out dated. – Rafe Mar 13 '13 at 21:32

4 Answers4

3

It's currently not possible, but you may upvote this enhancement here: http://code.google.com/p/gmaps-api-issues/issues/detail?id=4633

UPDATE

Recently, Google implemented this feature for polylines and polygons in Google Maps Android API v2 and marked issue 4633 as Fixed.

See information about stroke patterns in the Shapes Guide. See an example in the Polylines and Polygons tutorial.

You can also read the corresponding blog post here:

https://maps-apis.googleblog.com/2017/02/styling-and-custom-data-for-polylines.html

xomena
  • 31,125
  • 6
  • 88
  • 117
MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
1

First of all, take a look on the API https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Polyline

it is not yet possible with v2, but on v3 javascript API, it already is, look here: https://developers.google.com/maps/documentation/javascript/overlays#PolylineSymbols

But it seems that it's possible to use this v3 javascript API in an android app, look here: https://developers.google.com/maps/articles/android_v3

Maybe, this will help you

Xavjer
  • 8,838
  • 2
  • 22
  • 42
1

Find a LatLng at a distance of radius units from center LatLng on Map now convert both these LatLngs to screenCoordinates

Use the formula used to construct a cirle x = Rsin(theta) , y = Rcos(theta)

you divide the circle into N segments and then draw polylines(drawn on map) on the circumference of the circle converting the screen coordinates to LatLngs

more the number of N more it looks like a circle , I have used N = 120 according the zoom level ,I am using 13.

private void addDottedCircle(double radius) {//radius is in kms

    clearDottedCircle();


    LatLng center,start,end;
    Point screenPosCenter,screenPosStart,screenPosEnd;
    Projection p = mMap.getProjection();

    center = searchCenterMarker.getPosition();
    start = new LatLng(center.latitude + radius/110.54,center.longitude);
    // radius/110.54 gives the latitudinal delta we should increase so that we have a latitude at radius distance
    // 1 degree latitude is approximately 110.54 kms , so the above equation gives you a rough estimate of latitude at a distance of radius distance 


    screenPosCenter = p.toScreenLocation(center);
    screenPosStart = p.toScreenLocation(start);

    double R = screenPosCenter.y - screenPosStart.y;
    int N = 120;//N is the number of parts we are dividing the circle
    double T = 2*Math.PI/N;
    double theta = T;

    screenPosEnd = new Point();
    screenPosEnd.x = (int)(screenPosCenter.x-R*Math.sin(theta));
    screenPosEnd.y = (int) (screenPosCenter.y-R*Math.cos(theta));
    end = p.fromScreenLocation(screenPosEnd);

    for(int i =0;i<N;i++){
        theta+=T;
        if(i%2 == 0){
            //dottedCircle is a hashmap to keep reference to all the polylines added to map
            dottedCircle.add(mMap.addPolyline(new PolylineOptions().add(start,end).width(5).color(Color.BLACK)));

            screenPosStart.x = (int) (screenPosCenter.x-R*Math.sin(theta));
            screenPosStart.y = (int) (screenPosCenter.y-R*Math.cos(theta));
            start = p.fromScreenLocation(screenPosStart);
        }
        else{
            screenPosEnd.x = (int)(screenPosCenter.x-R*Math.sin(theta));
            screenPosEnd.y = (int) (screenPosCenter.y-R*Math.cos(theta));
            end = p.fromScreenLocation(screenPosEnd);
        }

    }

}

Image after drawing the dotted circle

D V Ramana
  • 1,136
  • 11
  • 13
0

If you are still looking for an answer have a look at this :

How to draw dashed polyline with android google map sdk v2?

Community
  • 1
  • 1
DrkStr
  • 1,752
  • 5
  • 38
  • 90