为OpenLayers转换GPS坐标 [英] Transforming GPS coordinates for OpenLayers

查看:1383
本文介绍了为OpenLayers转换GPS坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的坐标为48.3185005,14.2853003(由奥地利林茨协调)我从navigator.geolocation.getCurrentPosition()或Google地图地理编码API获得。
现在我想在地图上显示这一点。



地图显示正确的位置需要进行哪些转换,以及如何执行这些转换的OpenLayers?
目前,我总是在非洲以东的某个地方。 这是因为OpenStreetMap数据是一个投影坐标系统,称为Web墨卡托投影仪,即以米为单位,而您的GPS数据为纬度/经度。这就是为什么所有点都出现在非洲西海岸的海洋中,就像在以米为单位覆盖整个地球的坐标系中一样,180,180和-90,90范围内的任何坐标似乎都在这个小区域内加纳海岸。我注意到你在非洲东部的原帖中,但在评论中,你说大西洋,我认为你的意思是西部,这与我的解释一致。这是正确的吗?



通过指定不同的地图投影和显示投影,您可以在地图构造函数中处理这个问题:请参阅 http://docs.openlayers.org/library/spherical_mercator.html



你需要一些东西:

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

EPSG:3857(最初为900913)是Spherical Mercator的正式名称,并在此与4326经纬度)内置于OpenLayers中。


I am building a project in JavaScript that uses OpenLayers with an OpenStreetMap layer.

I have the coordinates "48.3185005, 14.2853003" (the coordinated of Linz, Austria) which I get from either navigator.geolocation.getCurrentPosition() or the Google Maps Geocoding API. Now I want to show this point on the map.

Which transformations are necessary for the map to display the correct location and how do I do these transformations with OpenLayers? At the moment, I am always getting some point east of Africa.

解决方案

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.

这篇关于为OpenLayers转换GPS坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆