如何计算一条线上的 x 个点?

How to calculate x number of points on a line?

我正在 google 地图上绘制折线。给定起点和终点(纬度、经度)坐标,我怎样才能得到那条线上的 [​​=20=] 个点数?

我尝试应用数学概念,例如直线方程 y = mx + c 或什至 (x-x1)/(x1-x2) = (y-y1)/(y1-y2) 但这些方法不起作用。世界不是平的。查找 latitude/longitude 值的直线中所有点的公式是什么?有人对此有任何想法吗?我相信我必须应用这个等式:https://en.wikipedia.org/wiki/Mercator_projection

编辑: 有人建议尝试将 lat/lng 转换为点,然后进行数学运算,然后再转换回 lat/lng。这样做时似乎有很大的余量或错误。纬度是准确的,但经度完全不准确。 TILE_SIZE = 256, Google returns for Google Maps

的图块大小
public GoogleMapsProjection2() {
    this._pixelOrigin = new PointF(TILE_SIZE / 2.0, TILE_SIZE / 2.0);
    this._pixelsPerLonDegree = TILE_SIZE / 360.0;
    this._pixelsPerLonRadian = TILE_SIZE / (2 * Math.PI);
}

public PointF fromLatLngToPoint(double lat, double lng, int zoom) {
    PointF point = new PointF(0, 0);

    point.x = _pixelOrigin.x + lng * _pixelsPerLonDegree;

    // Truncating to 0.9999 effectively limits latitude to 89.189. This is
    // about a third of a tile past the edge of the world tile.
    double siny = bound(Math.sin(degreesToRadians(lat)), -0.9999, 0.9999);
    point.y = _pixelOrigin.y + 0.5 * Math.log((1 + siny) / (1 - siny)) * -_pixelsPerLonRadian;

    int numTiles = 1 << zoom;
    point.x = point.x * numTiles;
    point.y = point.y * numTiles;
    return point;
}

public PointF fromPointToLatLng(PointF point, int zoom) {
    int numTiles = 1 << zoom;
    point.x = point.x / numTiles;
    point.y = point.y / numTiles;

    double lng = (point.x - _pixelOrigin.x) / _pixelsPerLonDegree;
    double latRadians = (point.y - _pixelOrigin.y) / -_pixelsPerLonRadian;
    double lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2);
    return new PointF(lat, lng);
}

public final class PointF {
    public double x;
    public double y;

    public PointF(double x, double y) {
        this.x = x;
        this.y = y;
    }
}

Google Maps polyline 中的线段是测地线。在球形地球近似中,这是一个大圆。使用投影将具有单个线段(您的起点和终点在 lat/long 坐标中)的多段线渲染到二维地图上,但它仍然是测地线(大圆)。

GIS stack exchange has this question of interpolating two (latitude, longitude) coordinates to compute waypoints. The answer suggests using GeographicLib, which has a java library, and provides a JavaScript example。 latitude/longitude 坐标中的结果 waypoints 是您对折线的输入。

最好在latitude/longitude坐标系中进行插值,以免投影或离散化放大误差。