Javascript 如何将 UTM 转换为纬度/经度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2683739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:27:11  来源:igfitidea点击:

How to convert UTM to Lat/Long?

javascriptmap-projectionsproj4jsutm

提问by Josh

Is there a way to convert UTMto Lat/Long in Javascript? I have seen another thread on this but it was in Java and Python which won't help me much. Please let me know, thanks.

有没有办法在 Javascript 中将UTM转换为纬度/经度?我已经看到了另一个线程,但它是用 Java 和 Python 编写的,这对我没有多大帮助。请让我知道,谢谢。

回答by Richard

You could use Proj4js, as follows.

您可以使用 Proj4js,如下所示。

Download Proj4JS from GitHub, using thislink.

使用链接从 GitHub 下载 Proj4JS 。

The following code will convert from UTM to longitude latitude

以下代码将从 UTM 转换为经度纬度

<html>
<head>
  <script src="proj4.js"></script>

  <script>
    var utm = "+proj=utm +zone=32";
    var wgs84 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
    console.log(proj4(utm,wgs84,[539884, 4942158]));
  </script>
</head>
<body>

</body>
</html>

In this code, the UTM zone is 32, as should be obvious. The Easting is 539884, and the Northing is 4942158. The result is:

在这段代码中,UTM 区域是 32,这应该是显而易见的。东距为 539884,北距为 4942158。结果为:

[9.502832656648073, 44.631671014204365] 

Which is to say 44.631671014204365N, 9.502832656648073E. Which I have verifiedis correct.

也就是说 44.631671014204365N,9.502832656648073E。我已经验证是正确的。

If you need other projections, you can find their strings here.

如果您需要其他投影,您可以在此处找到它们的字符串。