Transforming GPS coordinates for OpenLayers

自闭症网瘾萝莉.ら 提交于 2019-12-06 09:03:21

This is because OpenStreetMap data is a projected coordinate system, known as Web Mercator, ie, it is in meters, whereas your GPS data are in lat/lon. This is why all points appear to be in the sea off the West coast of Africa, as in a coordinate system covering the whole globe in meters, any coordinates in the range 180,180 and -90,90 will appear to be in that small area off the coast of Ghana. I notice in your original post you said East of Africa, but in a comment, you said Atlantic Ocean, from which I am assuming you meant West, which is consistent with my explanation. Is this correct?

You can deal with this in you map constructor by specifying a different map projection and display projection: see http://docs.openlayers.org/library/spherical_mercator.html

You want something along the lines of:

var map = new OpenLayers.Map("map", {
  projection: new OpenLayers.Projection("EPSG:900913"),
  displayProjection: new OpenLayers.Projection("EPSG:4326")
});

EPSG:3857 (originally 900913) is the official designation for Spherical Mercator and conversion between this and 4326 (lat/lon) is built into OpenLayers.

Would it simply be that you are mixing the values, the Point (14.2853003, 48.3185005) is in Yemen, and Point (48.3185005, 14.2853003) is in Austria..So check documentation whether the latitude & longitude values are given in different order than you think of

This should set your map in the right location.

map.setCenter(new OpenLayers.LonLat(14.2853003, 48.3185005).transform('EPSG:4326', map.getProjectionObject()), 5);

You only need to know the input coordinate reference and use the getProjectObject function to get the target reference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!