This calculator parses latitude and longitude coordinates in a variety of formats and outputs a selection of widely used formats. It also provides links to the coordinates on various internet maps: Open Street Map, Google Maps, and Bing Maps.

Here are a variety of global coordinates to demonstrate the cabalibities and variety of accepted input formats. Click on any of the following to see that the given input is parsed:

- Sydney Opera House: 33.8568° S, 151.2153° E
- Great Pyramid of Giza: 29° 58' 45" N, 31° 8' 3.12" E
- Machu Picchu: -13:9:47.2,-72:32:42
- Eiffel Tower: 48:51:30N, 2:17:40E
- Golden Gate Bridge: N 37.8199, W -122.4783
- Taj Mahal: 27.1751~78.0421
- Just a longitude: -40.334°W
- Just a latitude: 21:37:23 S

`(([NEWS]?)[ \t]*(-?)([0-9]{1,3})(?:[ \t\:°]+([0-9]{1,2}))?(?:[ \t\:\']+([0-9]{1,2}))?(\.[0-9]+)?[ \t°\'\"]*)([NEWS]?)`

To break that down:

`[NEWS]?`

-- The optional "north", "south", "east" and "west" symbols that are at often at the beginning or end of a coordinate`[ \t]*`

or`[ \t\:°]+`

or`[ \t\:\']+`

or`[ \t°\'\"]*`

-- Various whitespace and separators`[0-9]{1,3}`

-- A one to three digit number`\.[0-9]+`

-- A decimal point and the digits that follow it`()`

-- Capturing group parenthesis for pulling out whatever is contained`(?:)`

-- Non-capturing parenthesis used just for precedence and not for capturing

- This regex is applied twice to the input, once to pull out the latitude and a second time to pull out the longitude.
- Each coordinate is converted from its input format into decimal degrees.
- Seconds are divided by 60 to get minutes
- Minutes are divided by 60 to get degrees

- Which coordinate is latitude and which is longitute is taken from their positions if not specified by cardinal directions
- Further checks on the input are performed:
- Degrees are within bounds (-180 to 180 for longitude, -90 to 90 for latitude)
- One coordinate is latitude and the other longitude (not two "south" coordinates, for example)
- The latitude coordinate is before the longitude coordinate (the two are swapped if they are in the wrong order)

- The number of significant figures in the input are calculated so that the output can use the same accuracy as the input
- The coordinates are outputted in various formats
- Fractional degrees are multiplied by 60 to get minutes
- Fractional minutes are multiplied by 60 to get seconds
- Decimals are rounded to the same number of significant figures as were in the input
- A formatting system is used to replace letters in a format string to easily create various formats
`D`

: Decimal degrees`d`

: Degrees without the decimal`M`

: Decimal minutes`m`

: Minutes without the decimal`S`

: Decimal seconds`s`

: Seconds without the decimal`g`

: A negative sign (if present)`N`

: The cardinal direction symbol ("N", "S", "E", or "W")

`"D° N"`

would represent a decimal degrees format and`"gd:m:S"`

would represent a degrees, minutes, seconds format.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Copyright Stephen Ostermiller 2020-2020