Skip to content

Commit

Permalink
fix: clearer dms parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Apr 4, 2023
1 parent fd10f3e commit ca264ad
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/map/utils/parseDMS.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
export function parseDMS(input: string): [number, number] {
let parts: string[] = input.split(/[^\d\w\.]+/);
let lat = convertDMSToDD(parts[0], parts[1], parts[2], parts[3]);
let lng = convertDMSToDD(parts[4], parts[5], parts[6], parts[7]);
let lat = convertDMSToDD(parts.slice(0, 4));
let lng = convertDMSToDD(parts.slice(4));

return [lat, lng];
}

function convertDMSToDD(
degrees: string,
minutes: string,
seconds: string,
direction: string
): number {
function convertDMSToDD(dmsd: string[]): number {
const [degrees, minutes, seconds, direction] = dmsd;
let dd = Number(degrees) + Number(minutes) / 60 + Number(seconds) / (60 * 60);

if (direction == 'S' || direction == 'W') {
if (direction === 'S' || direction === 'W') {
dd = dd * -1;
} // Don't do anything for N or E
return dd;
Expand Down

0 comments on commit ca264ad

Please sign in to comment.