amMap美国地图中的纬度/经度坐标不正确。

6

我正在使用usaLow.js地图构建一个地图。在地图初始化时,我调用一个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();

这个位置应该在印第安纳州,但是我看到标记出现在这里:misplaced_marker 当不使用世界地图时,经纬度坐标需要转换吗?如果需要,如何进行转换?
编辑:修正了JSON字符串中的拼写错误。

尝试将“centered:false”属性添加到地图图像中。 - bhanu.cs
1
你有检查控制台吗?除非是打字错误,否则你的响应数据无效的JSON。试试这个:[{"latitude": "40.4258686","longitude": "-86.9080655"}]。你可能看到了一个默认位置。 - sideroxylon
嘿,谢谢,那确实是个笔误。我没有包含JSON对象中的所有数据,所以我一直在手动输入它。 - Anthony Veach
我尝试使用"centered:false",但似乎只是调整标记的左上角或中心是否使用左上值。这个距离并不考虑这一点。 - Anthony Veach
2个回答

9
似乎你正在使用一个未校准的美国地图(usaLow.js)。该地图由于视觉效果而失真,因此不兼容真实的纬度/经度坐标。
为了解决这个问题,你需要使用已校准的地图之一。以下是选项:
选项1:usa2Low.js
它是针对美国本土进行墨卡托校准的。标记应该可以正确绘制,除了阿拉斯加和夏威夷,该区域会有位移。

enter image description here

选项2:usaMercatorLow.js

这张地图完全支持包括阿拉斯加和夏威夷在内的坐标,但可能不太吸引人:

enter image description here

这两张地图都包含在JavaScript Maps中。


1

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

如果我知道我要在阿拉斯加或夏威夷绘制一个点,我可以将真实的纬度/经度进行缩放/平移,以便在Ammap上起作用。为此,我只需要在Ammap上找到阿拉斯加的Anchorage和Juneau两个点。使用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)));

                }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接