There must be some proven and tested method out there to do this, but here is a way you could do it with the Maps API:
- Convert the lat/lng coordinates to pixels
- Interpolate in the pixel plane
- Convert back to lat/lng
This is mostly pretty straightforward; the one hassle is figuring out how to deal with lines that cross the 180 meridian or a pole.
Here's some semi-tested code that may give you a place to start:
function mercatorInterpolate( map, latLngFrom, latLngTo, fraction ) {
// Get projected points
var projection = map.getProjection();
var pointFrom = projection.fromLatLngToPoint( latLngFrom );
var pointTo = projection.fromLatLngToPoint( latLngTo );
// Adjust for lines that cross the 180 meridian
if( Math.abs( pointTo.x - pointFrom.x ) > 128 ) {
if( pointTo.x > pointFrom.x )
pointTo.x -= 256;
else
pointTo.x += 256;
}
// Calculate point between
var x = pointFrom.x + ( pointTo.x - pointFrom.x ) * fraction;
var y = pointFrom.y + ( pointTo.y - pointFrom.y ) * fraction;
var pointBetween = new google.maps.Point( x, y );
// Project back to lat/lng
var latLngBetween = projection.fromPointToLatLng( pointBetween );
return latLngBetween;
}
I'm not 100% sure about the part that handles lines that cross the 180 meridian, but it works OK in the few quick tests I tried.