OpenLayers:将GPS坐标转换为EPSG:25832

OpenLayers:将GPS坐标转换为EPSG:25832,openlayers,Openlayers,我想通过点击按钮获得GPS坐标,并将其更改为EPSG:25832格式以使地图居中。以下是我到目前为止编写的代码: jQuery('#btnGPS').click(function() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(success); } else { alert("Not Supported!"); } }); function success(posi

我想通过点击按钮获得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的Position对象工作正常,但我无法使OpenLayers转换函数正常工作。我正在使用最新的标准OpenLayers


我是OpenLayers的新手,所以请详细说明解决方案。提前感谢。

您需要使用proj4js。以下是OpenLayers的说明链接:。 确保按照说明添加EPSG:25832的定义