如何将 WGS84 坐标转换为 UTM?

How to convert WGS84 coordinate to UTM?

如何使用 JavaScript 将地理坐标从 WGS 84 转换为 UTM?

我尝试使用 proj4js,但它产生了这些坐标:32U 5114272 1633427,而 external sources 告诉我们,32U 688260 5338516 是正确的。

您可能对 Lon/Lat 感到困惑。如果将 Lon (x) 设置为 11... 并将 Lat (y) 设置为 48...,那么一切都会按预期进行.

proj4.defs("EPSG:32632","+proj=utm +zone=32"); // https://epsg.io/32632

const sourceProj = new proj4.Proj('WGS84');
const destProj = new proj4.Proj('EPSG:32632');

function calc() {
  const x = parseFloat(document.getElementById('srcX').value)
  const y = parseFloat(document.getElementById('srcY').value)

  const p = new proj4.Point(x, y);
  const r = proj4.transform(sourceProj, destProj, p);

  document.getElementById('tgtX').value = r.x
  document.getElementById('tgtY').value = r.y
  console.log(x, y, p, r, r.x, r.y)
}

calc()
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.7.2/proj4.js"></script>
<pre>

From WGS84
Lon: <input type="number" id="srcX" value="11.532256" onchange="calc()"/>°
Lat: <input type="number" id="srcY" value="48.171974" onchange="calc()"/>°

To UTM 32U
X  : <input type="number" id="tgtX" value="" readonly/>
Y  : <input type="number" id="tgtY" value="" readonly/>

</pre>