1

I have one simple question. I wanted to draw a google.maps.Polygon around google.maps.Polyline. I implemented it by mixing solutions mentioned in How to draw a polygon around a polyline in JavaScript? . My question is about the wideness of the buffer. If u look at the example in https://coderwall.com/p/zb_zdw/buffered-polyline you can see that the buffer is wider when the polyline is horizontal. When the line is vertical buffer is smaller. Why is that? Is that correct? Example from my program: https://ibb.co/i2m2BF

Community
  • 1
  • 1
  • I switched over TurfJS http://turfjs.org/docs/#buffer that recently (what a good luck) fixed a similar issue in their library. It works just fine and also accept miles and kilometers, as distance units – Fausto R. May 22 '17 at 15:17

1 Answers1

1

The width of the polygon is set in degrees. From the code:

var distance = 10 / 111.12, // Roughly 10km)

The length of a degree of longitude varies with latitude.

geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • 1
    Thanks, it makes sense now but unfortunately it's a problem for me. I should make an area of 5 miles around the polyline and this solution is not precise. Do you know about some solution that would help me? Because this means that if u have horizontal line the buffer will be 2 times bigger than in vertical line. (90 vs 180 degrees) – Palo Lieskovsky Mar 05 '17 at 18:54
  • 1
    I implemented my whole program and all other functions work perfect. This one bothers me but i don't know how i could change it and still have a polygon as a buffer around polyline. – Palo Lieskovsky Mar 05 '17 at 19:02