Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate complex polygon with javascript
    text
    copied!<p>I want to create a polygon by route direction like here: <a href="https://i.imgur.com/olGmuN6.png" rel="nofollow noreferrer">http://i.imgur.com/olGmuN6.png</a> so I write this:</p> <pre><code>directionService.route(request, function(result, status) { if (status == google.maps.DirectionsStatus.OK) { directionsRenderer.setDirections(result); var r = []; var z = 0.5; var bla = result.routes[0].overview_path; for(var i=0 in result.routes[0].overview_path) { r.push(new google.maps.LatLng(bla[i].lat()+z, bla[i].lng()-z)); } bla.reverse(); for(var x=0 in bla) { r.push(new google.maps.LatLng(bla[x].lat()-z, bla[x].lng()+z)); } var prva = new google.maps.Polyline({ path: result.routes[0].overview_path, strokeColor: "#00000", strokeOpacity: 1.0, strokeWeight: 2 }); prva.setMap(map); druga = new google.maps.Polygon({ paths: r, strokeColor: "#FF0000", strokeOpacity: 0.8, strokeWeight: 2, fillColor: "#FF0000", fillOpacity: 0.35 }); druga.setMap(map); } else { alert("Directions query failed: " + status); } }); </code></pre> <p>but in some cases is good in some cases not, so my code produce this:</p> <pre><code> BAD case: </code></pre> <p><img src="https://i.stack.imgur.com/w5lqL.png" alt="enter image description here"> GOOD: <img src="https://i.stack.imgur.com/DH88N.jpg" alt="enter image description here"></p> <p>So how I can solve this problem to get nice polygon by route direction ??? Does someody have idea?</p> <p>How I can implement this into my code: <a href="http://i.imm.io/1gMu5.png" rel="nofollow noreferrer">http://i.imm.io/1gMu5.png</a></p> <p>Is there some other way than this to create what I need...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload