我正在谷歌地图上绘制多段线。给定起点和终点(纬度、经度)坐标,如何获得该直线上的“x”点数?
我曾尝试应用数学概念,如直线方程y=mx+c,甚至(x-x1)/(x1-x2)=(y-y1)/(y1-y2),但这些方法不起作用。世界不是平坦的。在一条直线上查找纬度/经度值的所有点的公式是什么?有人对此有什么想法吗?我认为我必须应用这个等式:
https://en.wikipedia.org/wiki/Mercator_projection
编辑:
有人建议尝试将纬度/液化天然气转换为点,然后进行数学运算,然后再转换回纬度/液化天然气。这样做时,似乎有很大的差距或错误。纬度是准确的,但经度完全不准确。TILE\u SIZE=256,Google为Google Maps返回的TILE大小
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;
}
}