【问题标题】:Latitude/Longitude coordinates are not correct in amMap USA mapamMap 美国地图中的纬度/经度坐标不正确
【发布时间】:2015-11-18 04:19:23
【问题描述】:

我正在使用 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 字符串拼写错误

【问题讨论】:

  • 尝试在地图图像中添加“centered:false”属性
  • 你检查过控制台吗?除非是拼写错误,否则您的响应数据是无效的 JSON。试试这个:[{"latitude": "40.4258686","longitude": "-86.9080655"}]。您可能看到的是默认位置。
  • 嘿,谢谢,这实际上是一个错字。我没有包含 JSON 对象中的所有数据,所以我是手动输入的。
  • 我确实尝试过使用“centered:false”,但如果标记使用标记左上角或中心的上/左值,这似乎只是调整。这个距离不能说明这一点。

标签: javascript amcharts ammap


【解决方案1】:

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

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

选项 1:usa2Low.js

它经过墨卡托校准,适用于美国大陆。除阿拉斯加和夏威夷外,该区域已被移动,标记应该可以绘制。

选项 2:usaMercatorLow.js

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

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

【讨论】:

    【解决方案2】:

    我知道这是一个老问题,但我想出了一个解决方案,可以帮助其他人使用 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)));
    
                    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      相关资源
      最近更新 更多