【问题标题】:OpenLayers: transform GPS coordinates to EPSG:25832OpenLayers:将 GPS 坐标转换为 EPSG:25832
【发布时间】:2013-08-07 16:42:15
【问题描述】:

我想通过单击按钮获取 GPS 坐标并将其更改为 EPSG:25832 格式以使我的地图居中。到目前为止,这是我编写的代码:

jQuery('#btnGPS').click(function() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(success);
  } else {
    alert("Not Supported!");
  }
});

function success(position) {
  alert(position.coords.longitude + ',' + position.coords.latitude);
  var SRS_MAP = new OpenLayers.Projection("EPSG:25832"); 
  var SRS_LONLAT = new OpenLayers.Projection("EPSG:4326"); 
  var center = new OpenLayers.LonLat(position.coords.longitude,position.coords.latitude); 
  var test = center.transform(SRS_LONLAT,SRS_MAP); 
  alert(test);
}

最后是我的地图对象:

map = new OpenLayers.Map('map',{
      controls: [
                    new OpenLayers.Control.Navigation(),
                    new OpenLayers.Control.PanZoomBar(),
                    new OpenLayers.Control.ScaleLine(),
                    new OpenLayers.Control.KeyboardDefaults()
                ],
                projection: new OpenLayers.Projection("EPSG:25832"),
                displayProjection: new OpenLayers.Projection("EPSG:4326"),
                units: 'm',
                maxExtent: new OpenLayers.Bounds(356570.500,5442150.416,383807.687,5462691.920),
                maxResolution: 'auto',
                numZoomLevels: 8
            });

我总是得到相同的坐标,根本没有任何变换。具有 lon 和 lat 的位置对象工作正常,但我无法让 OpenLayers 变换函数正常工作。我正在使用最新的标准 OpenLayers。

我对 OpenLayers 很陌生,所以请对解决方案非常具体。提前致谢。

【问题讨论】:

    标签: openlayers


    【解决方案1】:

    您需要使用 proj4js。这是 OpenLayers 说明的链接:http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js。 确保按照说明添加 EPSG:25832 的定义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 2016-09-28
      • 2021-12-23
      • 1970-01-01
      相关资源
      最近更新 更多