title: How to sort points in a Google maps polygon so that lines do not cross?
body: <p>I am trying to make a map where a user can outline any shape they would like.  But I am running into an issue where users can select points that will make the lines of the polygon cross and exclude area's that I would like to include.  </p>
  
  <p>To see what i'm talking about go to <a href="http://polygon.abemiester.com" rel="nofollow noreferrer">this page</a> and take the following steps:</p>
  
  <ol>
  <li>click 4 points to make the 4 corners
  of a box</li>
  <li>click in between each of the 4
  points you just made to further
  define the perimter of the box</li>
  <li>click done</li>
  </ol>
  
  <p>You should see something like this:</p>
  
  <p><a href="https://web.archive.org/web/20140915060853/https://polygon.abemiester.com/1.bmp" rel="nofollow noreferrer"><img src="https://web.archive.org/web/20140915060853/https://polygon.abemiester.com/1.bmp" alt="alt text"></a></p>
  
  <p>Is there an easy way to solve this problem, or am I basically dealing with a "Traveling Salesman" type situation here?  All the logic is done in javascript so feel free to "view source" if you would like to see how i'm doing this.</p>