如何使用JavaScript将地理坐标从WGS 84转换为UTM?
我尝试使用proj4js,但是它得到了以下坐标:32U 5114272 1633427
,而外部来源告诉我们32U 688260 5338516
是正确的。
发布于 2021-03-05 14:26:23
你可能和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>
https://stackoverflow.com/questions/66490626
复制相似问题