我从MaxMind建立了一个城市数据库,其中包括数据库中每个城市的lat/lng值。我还整理了一张北美地图,我希望在地图的x/y坐标上出现一个图标,它是从城市数据库记录的lat/lng坐标导出的。
根据我的理解,我需要先找出地图的左/上界(lat/lng -> x/y),然后用它作为北美城市x/y之间线性关系的区别。最后,根据地图的大小,只需进行几个简单的除法和减法操作,就可以确定位置。
然而,我似乎不知道如何做以下工作:
有什么想法吗?
-编辑--
输出图(北美)是一个连续圆柱:"Miller圆柱形投影“。投影
发布于 2012-08-02 09:25:14
纬度和经度是在地球上绘制的假想线,所以你可以精确地定位世界上的任何位置。简单地说,它们是平面的X和Y弦。纬度是一条从北向南的垂直线,北极为90度,南极为-90度。
而经度则是一条由东向南的水平线,西侧为-180度,东面为180度。
您可以通过假设html容器的宽度为世界的宽度,并将同样的宽度应用于高度,将latLng转换为像素共弦。
公式-经度像素
(givenLng*widthOfContainerElement)/360其中360是以度为单位的总经度。
公式-Latitude -圆柱形
(givenLat*heightOfContainerElement)/180其中360是度的总经度。
//Height is calculated from the bottom如果你还需要澄清,请告诉我。
发布于 2018-08-06 12:27:30
下面是一个墨卡托投影的Javascript实现,它只返回正值(笛卡尔坐标系的屏幕),并说明了球面>平面转换:
// get x
var x = (lng + 180) * (mapWidth / 360);
// convert from degrees to radians
var latRad = lat * Math.PI / 180;
// get y value
var mercN = Math.log(Math.tan((Math.PI / 4) + (latRad / 2)));
var y = (mapHeight / 2) - (mapWidth * mercN / (2 * Math.PI));发布于 2019-08-20 16:32:05
这是一个很老的问题,但公认的答案有一些.细微差别..。
通常,这是为卫星/航空图像,这通常伴随着一个“缩放水平”。
这种缩放水平大致(我的意思是粗略地)转换为“地面采样距离”或GSD,如果提供的话,它表示图像中每像素的厘米。
你经常会看到变焦- 18,19,20或21。
需要注意的问题之一是,地球不是平的,也不是完全球形的,因此,有许多不同的“投影”方法可用于将地球表面的三维坐标转换为屏幕上的二维图像。这些投影方法中最流行和最广泛使用的是Mercator投影。
Google提供了一种方法,它使用Mercator投影来提供x和y的像素坐标。
然后,我们可以使用“缩放级别”来缩放坐标,以适应我们的图像。
interface LatLngLiteral {
lat: number;
lng: number;
}
interface Coordinate {
x: number;
y: number;
}
const project = (latLng: LatLngLiteral): Coordinate => {
const TILE_SIZE: number = 256;
let siny: number = Math.sin((latLng.lat * Math.PI) / 180);
// 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.
siny = Math.min(Math.max(siny, -0.9999), 0.9999);
return {
x: TILE_SIZE * (0.5 + latLng.lng / 360),
y: TILE_SIZE * (0.5 - Math.log((1 + siny) / (1 - siny)) / (4 * Math.PI))
};
};
export function formatToPoint(latLng: LatLngLiteral, zoom: number): Coordinate {
// Get the world coordinates in pixels
const worldCoordinate: Coordinate = project(latLng);
// Scale to fit our image
const scale: number = Math.pow(2, zoom);
// Apply scale to world coordinates to get image coordinates
return {
x: Math.floor(worldCoordinate.x * scale),
y: Math.floor(worldCoordinate.y * scale)
}
}https://stackoverflow.com/questions/8898120
复制相似问题