【发布时间】:2011-01-07 10:00:20
【问题描述】:
我有这张图片。这是英国的地图(不包括南爱尔兰):
我已经成功地获得了一个纬度和经度,并将其绘制到这张地图上,方法是获取英国最左边的经度和最右边的经度,并使用它们来计算在地图上放置点的位置。
这是代码(用于Processing.js,但可以用作js或任何东西):
// Size of the map
int width = 538;
int height = 811;
// X and Y boundaries
float westLong = -8.166667;
float eastLong = 1.762833;
float northLat = 58.666667;
float southLat = 49.95;
void drawPoint(float latitude, float longitude){
fill(#000000);
x = width * ((westLong-longitude)/(westLong-eastLong));
y = (height * ((northLat-latitude)/(northLat-southLat)));
console.log(x + ", " + y);
ellipseMode(RADIUS);
ellipse(x, y, 2, 2);
}
但是,我无法在这些值上实现墨卡托投影。这些图相当准确,但还不够好,这个投影可以解决它。
我不知道该怎么做。我找到的所有例子都在解释如何为全世界做这件事。 This 是一个很好的示例资源,解释了如何实现投影,但我无法让它工作。
另一个资源是Extreme points of the United Kingdom,我在其中获得了英国周围边界框的纬度和经度值。他们也在这里:
northLat = 58.666667;
northLong = -3.366667;
eastLat = 52.481167;
eastLong = 1.762833;
southLat = 49.95;
southLong = -5.2;
westLat = 54.45;
westLong = -8.166667;
如果有人能帮我解决这个问题,我将不胜感激!
谢谢
【问题讨论】:
标签: javascript geolocation projection processing.js proj4js