title: How to compute line segment intersections on a map
body: <p>I am working with Latitude / Longitude coordinates in a google map.</p>
  
  <p>I have two lines :</p>
  
  <ul>
  <li>Line A : 48.31508162629726, -2.591741396838972 to 48.40216156645915, -2.2218462112093404</li>
  <li>Line B : 48.383816077371215, -2.274292940053768 to 48.66103546935337, -1.7066197241571377</li>
  </ul>
  
  <p>I then use the following formula to find the point where they cross.</p>
  
  <pre><code>var XAsum = A.LngStart - A.LngEnd;
  var XBsum = B.LngStart - B.LngEnd;
  var YAsum = A.LatStart - A.LatEnd;
  var YBsum = B.LatStart - B.LatEnd;
  
  var LineDenominator = XAsum * YBsum - YAsum * XBsum;
  if(LineDenominator == 0.0)
      return false;
  
  var a = A.LngStart * A.LatEnd - A.LatStart * A.LngEnd;
  var b = B.LngStart * B.LatEnd - B.LatStart * B.LngEnd;
  
  var x = (a * XBsum - b * XAsum) / LineDenominator;
  var y = (a * YBsum - b * YAsum) / LineDenominator;
  </code></pre>
  
  <p>This tells me that the lines do indeed cross and returns the x and y values.</p>
  
  <p>However, when I plot the returned point, it is offset (not much) from the real intersection.</p>
  
  <p>Is there a better and just as fast algorithm I could use which will return me the correct intersection point ?</p>
  
  <p>It needs to be fast as I am iterating over a large number of lines (~1000).</p>
  
  <p>EDIT : Note this is giving me an error offset of around 7.5 meters</p>