Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latitude/Longitude coordinates are not correct in amMap USA map

I am building a map using the usaLow.js map. On map init, I call a json method that returns this data:

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

With this data I add to the map's data provider (mapData) with this:

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

like image 423
Anthony Veach Avatar asked Nov 18 '15 04:11

Anthony Veach


1 Answers

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.

To work around that, you will need to use one of the maps that are calibrated. The options are these:

Option 1: usa2Low.js

It is Mercator-calibrated for mainland US. The markers should plot OK, except for Alaska and Hawaii, that area displaced.

enter image description here

Option 2: usaMercatorLow.js

This map is fully compatible with coordinates, including Alaska and Hawaii. However, it might not look as appealing:

enter image description here

Both of those maps are bundled with JavaScript Maps.

like image 83
martynasma Avatar answered Sep 19 '22 02:09

martynasma