Latitude/Longitude amMap 美国地图中的坐标不正确
Latitude/Longitude coordinates are not correct in amMap USA map
我正在使用 usaLow.js 地图构建地图。在 map init 上,我调用了一个 json 方法,该方法 returns 此数据:
[{latitude: "40.4258686",longitude: "-86.9080655"}]
我将这些数据添加到地图的数据提供程序 (mapData) 中:
mapData.images = [];
for(var i = 0; i < resp.length; ++i){
mapData.images.push({
type: "circle",
color:"#FF0000",
latitude: parseFloat(resp[i].latitude),
longitude: parseFloat(resp[i].longitude)
});
}
map.validateData();
这个位置应该在印第安纳州,但这是我看到标记的地方:
不使用世界地图时lat/long坐标需要转换吗?如果可以,那该怎么做?
编辑:修复了 JSON 字符串拼写错误
您似乎在使用未经校准的美国地图。 (usaLow.js)为了视觉目的,这张地图被扭曲了,因此与真实的 latitude/longitude 坐标不兼容。
要解决这个问题,您将需要使用 校准过的地图之一。选项如下:
选项 1:usa2Low.js
它是针对美国大陆进行墨卡托校准的。标记应该绘制正常,除了阿拉斯加和夏威夷,该区域流离失所。
选项 2:usaMercatorLow.js
此地图与坐标完全兼容,包括阿拉斯加和夏威夷。但是,它可能看起来不那么吸引人:
这两张地图都与 JavaScript 地图捆绑在一起。
我知道这是一个老问题,但我想出了一个解决方案,可能会帮助其他人使用 AmCharts.maps.usa2High.
如果我知道我正在阿拉斯加或夏威夷绘制一个点,我可以将真实的 lat/lng 和 scale/translate 带到在 Ammap 上工作的 lat/lng。为此,我只需要在阿拉斯加的安克雷奇和朱诺的 Ammap 上获得 2 分。使用 Ammap 开发工具,我能够估算出这些位置。这是我如何让它工作的。我使用了一个名为 Big.js 的工具来更准确地进行数学运算 - https://github.com/MikeMcl/big.js/
注意: locations 是一个包含我的地址的数组。
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
if(locations[index].state.toLowerCase() == 'ak' || locations[index].state.toLowerCase() == 'alaska'){
//Use 2 points to translate the coordinates
//anchorage
//normal coords
var ax1 = new Big(61.2180556);
var ay1 = new Big(-149.90027780000003);
//ammap coords
var bx1 = new Big(20.7413);
var by1 = new Big(-115.1221);
//juneau
//normal coords
var ax2 = new Big(58.3019444);
var ay2 = new Big(-134.41972220000002);
//ammap coords
var bx2 = new Big(18.9596);
var by2 = new Big(-109.7574);
//find the scale of Ammaps Alaska vs. actual lat/lng coords
var latScale = (bx1.minus(bx2)).div(ax1.minus(ax2));
var lngScale = (by1.minus(by2)).div(ay1.minus(ay2));
//get the new translated point by using the 2 existing points and
lat = bx2.plus(latScale.times((new Big(lat)).minus(ax2)));
lng = by2.plus(lngScale.times((new Big(lng)).minus(ay2)));
}
if(locations[index].state.toLowerCase() == 'hi' || locations[index].state.toLowerCase() == 'hawaii'){
//Use 2 points to translate the coordinates
//honolulu
//normal coords
var ax1 = new Big(21.3069444);
var ay1 = new Big(-157.85833330000003);
//ammap coords
var bx1 = new Big(24.1081);
var by1 = new Big(-104.5377);
//normal coords
var ax2 = new Big(20.7983626);
var ay2 = new Big(-156.33192529999997);
//ammap coords
var bx2 = new Big(23.5082);
var by2 = new Big(-102.5078);
//find the scale of Ammaps Hawaii vs. actual lat/lng coords
var latScale = (bx1.minus(bx2)).div(ax1.minus(ax2));
var lngScale = (by1.minus(by2)).div(ay1.minus(ay2));
//get the new translated point by using the 2 existing points and
lat = bx2.plus(latScale.times((new Big(lat)).minus(ax2)));
lng = by2.plus(lngScale.times((new Big(lng)).minus(ay2)));
}
我正在使用 usaLow.js 地图构建地图。在 map init 上,我调用了一个 json 方法,该方法 returns 此数据:
[{latitude: "40.4258686",longitude: "-86.9080655"}]
我将这些数据添加到地图的数据提供程序 (mapData) 中:
mapData.images = [];
for(var i = 0; i < resp.length; ++i){
mapData.images.push({
type: "circle",
color:"#FF0000",
latitude: parseFloat(resp[i].latitude),
longitude: parseFloat(resp[i].longitude)
});
}
map.validateData();
这个位置应该在印第安纳州,但这是我看到标记的地方:
不使用世界地图时lat/long坐标需要转换吗?如果可以,那该怎么做?
编辑:修复了 JSON 字符串拼写错误
您似乎在使用未经校准的美国地图。 (usaLow.js)为了视觉目的,这张地图被扭曲了,因此与真实的 latitude/longitude 坐标不兼容。
要解决这个问题,您将需要使用 校准过的地图之一。选项如下:
选项 1:usa2Low.js
它是针对美国大陆进行墨卡托校准的。标记应该绘制正常,除了阿拉斯加和夏威夷,该区域流离失所。
选项 2:usaMercatorLow.js
此地图与坐标完全兼容,包括阿拉斯加和夏威夷。但是,它可能看起来不那么吸引人:
这两张地图都与 JavaScript 地图捆绑在一起。
我知道这是一个老问题,但我想出了一个解决方案,可能会帮助其他人使用 AmCharts.maps.usa2High.
如果我知道我正在阿拉斯加或夏威夷绘制一个点,我可以将真实的 lat/lng 和 scale/translate 带到在 Ammap 上工作的 lat/lng。为此,我只需要在阿拉斯加的安克雷奇和朱诺的 Ammap 上获得 2 分。使用 Ammap 开发工具,我能够估算出这些位置。这是我如何让它工作的。我使用了一个名为 Big.js 的工具来更准确地进行数学运算 - https://github.com/MikeMcl/big.js/
注意: locations 是一个包含我的地址的数组。
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
if(locations[index].state.toLowerCase() == 'ak' || locations[index].state.toLowerCase() == 'alaska'){
//Use 2 points to translate the coordinates
//anchorage
//normal coords
var ax1 = new Big(61.2180556);
var ay1 = new Big(-149.90027780000003);
//ammap coords
var bx1 = new Big(20.7413);
var by1 = new Big(-115.1221);
//juneau
//normal coords
var ax2 = new Big(58.3019444);
var ay2 = new Big(-134.41972220000002);
//ammap coords
var bx2 = new Big(18.9596);
var by2 = new Big(-109.7574);
//find the scale of Ammaps Alaska vs. actual lat/lng coords
var latScale = (bx1.minus(bx2)).div(ax1.minus(ax2));
var lngScale = (by1.minus(by2)).div(ay1.minus(ay2));
//get the new translated point by using the 2 existing points and
lat = bx2.plus(latScale.times((new Big(lat)).minus(ax2)));
lng = by2.plus(lngScale.times((new Big(lng)).minus(ay2)));
}
if(locations[index].state.toLowerCase() == 'hi' || locations[index].state.toLowerCase() == 'hawaii'){
//Use 2 points to translate the coordinates
//honolulu
//normal coords
var ax1 = new Big(21.3069444);
var ay1 = new Big(-157.85833330000003);
//ammap coords
var bx1 = new Big(24.1081);
var by1 = new Big(-104.5377);
//normal coords
var ax2 = new Big(20.7983626);
var ay2 = new Big(-156.33192529999997);
//ammap coords
var bx2 = new Big(23.5082);
var by2 = new Big(-102.5078);
//find the scale of Ammaps Hawaii vs. actual lat/lng coords
var latScale = (bx1.minus(bx2)).div(ax1.minus(ax2));
var lngScale = (by1.minus(by2)).div(ay1.minus(ay2));
//get the new translated point by using the 2 existing points and
lat = bx2.plus(latScale.times((new Big(lat)).minus(ax2)));
lng = by2.plus(lngScale.times((new Big(lng)).minus(ay2)));
}