简体   繁体   English

amMap USA地图中的纬度/经度坐标不正确

[英]Latitude/Longitude coordinates are not correct in amMap USA map

I am building a map using the usaLow.js map. 我正在使用usaLow.js地图构建地图。 On map init, I call a json method that returns this data: 在map init上,我调用一个返回此数据的json方法:

[{latitude: "40.4258686",longitude: "-86.9080655"}]

With this data I add to the map's data provider (mapData) with this: 有了这些数据,我就用这个添加到地图的数据提供者(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();

This location should be in Indiana, but this is where I see the marker: 这个位置应该在印第安纳州,但这是我看到标记的地方: misplaced_marker

Do lat/long coordinates need to be converted when not using world maps? 不使用世界地图时是否需要转换纬度/经度坐标? If so, how can that be done? 如果是这样,怎么办呢?

edit: Fixed JSON string typo 编辑:修正了JSON字符串错误

It seems like you are using a non-calibrated US map. 您似乎正在使用未经校准的美国地图。 (usaLow.js) This map is distorted for visual purposes and thus not compatible with real latitude/longitude coordinates. (usaLow.js)此地图因视觉目的而扭曲,因此与真实的纬度/经度坐标不兼容。

To work around that, you will need to use one of the maps that are calibrated. 要解决此问题,您需要使用其中一个校准的地图。 The options are these: 选项如下:

Option 1: usa2Low.js 选项1:usa2Low.js

It is Mercator-calibrated for mainland US. 它是墨卡托校准的美国大陆。 The markers should plot OK, except for Alaska and Hawaii, that area displaced. 除了阿拉斯加和夏威夷之外,标记应该是正确的。

在此输入图像描述

Option 2: usaMercatorLow.js 选项2:usaMercatorLow.js

This map is fully compatible with coordinates, including Alaska and Hawaii. 此地图与坐标完全兼容,包括阿拉斯加和夏威夷。 However, it might not look as appealing: 但是,它可能看起来不那么有吸引力:

在此输入图像描述

Both of those maps are bundled with JavaScript Maps. 这两个地图都与JavaScript地图捆绑在一起。

I know this is kind of an old question, but I came up with a solution that might help someone else using AmCharts.maps.usa2High. 我知道这是一个老问题,但我想出了一个可以帮助其他人使用AmCharts.maps.usa2High的解决方案。

If I know that I'm plotting a point in Alaska or Hawaii I can take real lat/lng and scale/translate it to a lat/lng that works on the Ammap. 如果我知道我正在阿拉斯加或夏威夷绘制一个点我可以采用真正的lat / lng并将其缩放/转换为适用于Ammap的lat / lng。 To do this I just needed 2 points on the Ammap In Alaska's case, Anchorage and Juneau. 要做到这一点,我只需要在Ammap In Alaska的案例中获得2分,安克雷奇和朱诺。 Using the Ammap dev tools I was able to approximate these locations. 使用Ammap开发工具,我能够近似这些位置。 Here is how I made it work. 这是我如何使它工作。 I used a tool called Big.js to do the math more accurately - https://github.com/MikeMcl/big.js/ 我使用了一个名为Big.js的工具来更准确地计算数学 - https://github.com/MikeMcl/big.js/

Note: locations is an array that holds my addresses. 注意: 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)));

                }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将纬度经度坐标转换为图像映射坐标 - Converting Latitude Longitude Coordinates to Image Map Coordinates 如何设置Cesium JS地图中心(坐标:纬度和经度) - How to set Cesium JS map center (coordinates: latitude & longitude) 使用标记从Google地图获取纬度/经度坐标 - Get latitude/longitude coordinates from a Google map using a marker 通过街道地址获取谷歌地图的坐标(纬度和经度) - 角度 - get the coordinates(latitude and longitude) of google map by street address - angular 将纬度和经度转换为 XY 坐标 - Converting Latitude and Longitude to XY Coordinates 将经度和纬度转换为图像上的坐标 - Converting Latitude and Longitude to coordinates on image 将经度纬度转换为平铺坐标 - Converting longitude latitude to tile coordinates 地图瓦片集的纬度和经度 - Latitude and longitude to map tile set 在 Google Map API 中创建三角形坐标的理想方法是什么,其中两个位置点由纬度和经度组成 - What is the Ideal way to create a Triangle-Coordinates in Google Map API with two location points consisting of latitude & longitude 从javascript打开原生地图应用程序,而不依赖于经度和纬度坐标 - Opening native map app from javascript without relying on longitude and latitude coordinates
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM