6

我正在使用 usaLow.js 地图构建地图。在 map init 上,我调用了一个返回此数据的 json 方法:

[{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();

这个位置应该在印第安纳州,但这是我看到标记的地方:错位标记

不使用世界地图时是否需要转换纬度/经度坐标?如果是这样,那该怎么做?

编辑:修正 JSON 字符串错字

4

2 回答 2

9

您似乎使用的是未经校准的美国地图。(usaLow.js) 此地图出于视觉目的而失真,因此与真实的纬度/经度坐标不兼容。

要解决此问题,您将需要使用校准的地图之一。选项如下:

选项 1:usa2Low.js

它经过墨卡托校准,适用于美国大陆。除阿拉斯加和夏威夷外,该地区的标记应绘制正常。

在此处输入图像描述

选项 2:usaMercatorLow.js

该地图与坐标完全兼容,包括阿拉斯加和夏威夷。但是,它可能看起来不那么吸引人:

在此处输入图像描述

这两个地图都与 JavaScript 地图捆绑在一起。

于 2015-11-18T06:05:44.340 回答
1

我知道这是一个老问题,但我想出了一个解决方案,可以帮助使用 AmCharts.maps.usa2High 的其他人。

如果我知道我正在阿拉斯加或夏威夷绘制一个点,我可以采用真正的纬度/经度并将其缩放/转换为适用于 Ammap 的经度/经度。为此,我只需要在阿拉斯加的安克雷奇和朱诺的 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)));

                }
于 2016-06-15T09:31:32.247 回答