简体   繁体   中英

Javascript to convert degrees, to decimal, and UTM

I´m trying to convert Degrees, Minutes and Seconds, to decimal degrees, and finally to UTM. Is there any example or library available for this purpose?

Thanks!

There are some useful libraries for doing this kind of thing, in particular geolib and utm-latlng .

Once we import these we can convert from Degrees, Minutes, Seconds with geolib and then to UTM with utm-latlng:

const geolib = require("geolib");
const UTM = require("utm-latlng");
const utm = new UTM();

const input = { lat: "34° 3′ 12.96″ N", lon: "118° 14′ 34.8″ W" };
const decimalCoords = geolib.toDecimal(input);

console.log("Input:", input);
console.log("Degrees/Minutes/Seconds To Decimal:", decimalCoords);
console.log("UTM:", utm.convertLatLngToUtm(decimalCoords.lat, decimalCoords.lon, 0));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM