Draw a dashed line on google v2 maps instead of solid

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

I know that you could do this if you override the onDraw overlay method in v1 , but the Overlay class no longer exists, so how else can this be achieved?

+4
source share
4 answers

This is not currently possible, but you can enhance this advantage here: http://code.google.com/p/gmaps-api-issues/issues/detail?id=4633

UPDATE

Google recently applied this feature to polylines and polygons in the Google Maps Android API v2 and issue 4633 was reported as fixed.

See stroke patterns in the Shape Guide . See the example in the tutorial, "Polylines and Polygons."

You can also read the corresponding blog post:

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

+3
source

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

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

But it seems that you can use this v3 API in an Android application, look here: https://developers.google.com/maps/articles/android_v3

Maybe this will help you

+1
source

Find LatLng at a distance of radii from the center of LatLng on the map now convert both of these LatLngs to screenCoordinates

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

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

more than N is more like a circle, I used N = 120 according to the zoom level, I use 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.xR*Math.sin(theta)); screenPosEnd.y = (int) (screenPosCenter.yR*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.xR*Math.sin(theta)); screenPosStart.y = (int) (screenPosCenter.yR*Math.cos(theta)); start = p.fromScreenLocation(screenPosStart); } else{ screenPosEnd.x = (int)(screenPosCenter.xR*Math.sin(theta)); screenPosEnd.y = (int) (screenPosCenter.yR*Math.cos(theta)); end = p.fromScreenLocation(screenPosEnd); } } } 

Image after drawing the dotted circle

+1
source

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

How to draw a dotted polyline using android google map sdk v2?

0
source

Source: https://habr.com/ru/post/1469071/


All Articles