How to divide line into three equal parts?

I have a problem with line division. I'm writing a program in JS/C++ generating KML files.

I was trying to divide a line using my own function (which is correct on cartesian space):

var part1Lon = startLon+((-startLon + endLon)/3);
var part1Lat = startLat +((-startLat + endLat)/3);

But when i visualized point [part1Lon, part1Lat] on Google Earth - and it's not on the line! (As I could have expected)

So, second attempt was to convert longitude and latitude to Mercator first, do calculations, and convert coordinates back to WGS. It produces similar result - point is not on the line.

What is correct algorithm or the correct projection for doing such operations?

• GE plots the line as a great circle arc. Cartesian math on spherical (or spheroidal) coordinates will be wrong every time. Mercator is always wrong for distance (spectacularly so at high latitudes). Lots of answers here on how to do lat1,lon1,lat2,lon2->distance,bearing and lat1,lon1,distance,bearing->lat2,lon2 calculation. You just need to third (and two-thirds) the distance from F1 with F2. – Vince Mar 28 '16 at 12:41
• Are you writing pure JS or are you using any libraries? – MappaGnosis Mar 28 '16 at 14:03