1

我想通过单击按钮获取 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 很陌生,所以请对解决方案非常具体。提前致谢。

4

1 回答 1

0

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

于 2014-01-28T11:09:44.763 回答