title: Solving Practical Problems with Golang Latitude and Longitude in DMS Format
date: 2022-05-30 10:53:00
toc: false
index_img: https://puep.qpic.cn/coral/Q3auHgzwzM4fgQ41VTF2rGpUMPpyPrsMm6TJcdtuTd00Qp3a7jkPEg/0
category:
- Go
tags: - Calculation
- Format
Problem#
Write a program that can calculate the distance between each pair of landing points in the table "Landing Points on Mars" and answer the following questions:
- Which two landing points are closest to each other?
- Which two landing points are farthest from each other?
Then, define a new world based on the table "Measured Radii of Various Planets" and perform the following calculations:
- Calculate the distance between London, UK (latitude 51°31', longitude 0°08') and Paris, France (latitude 48°51', longitude 2°21').
- Calculate the distance between your city and the capital city.
- Calculate the distance between Mount Sharp on Mars (latitude 5°4'48", longitude 137°51') and Olympus Mons (latitude 18°39', longitude 226°12').
Landing Points on Mars#
| Probe or Lander | Landing Point | Latitude | Longitude |
|---|---|---|---|
| Spirit | Columbia Memorial | South 14°34'6.2" | East 175°28'21.5" |
| Opportunity | Challenger | South 1°56'46.3" | East 354°28'24.2" |
| Curiosity | Bradbury Landing | South 4°35'22.2" | East 137°26'30.1" |
| InSight | Elysium Planitia | North 4°30'0.0" | East 135°54'0" |
Measured Radii of Various Planets#
| Planet | Radius/km | Planet | Radius/km |
|---|---|---|---|
| Mercury | 2439.7 | Jupiter | 69911 |
| Venus | 6051.8 | Saturn | 58232 |
| Earth | 6371.0 | Uranus | 25362 |
| Mars | 3389.5 | Neptune | 24622 |
Code#
Results#
Summary#
- Go language achieves object-oriented features of traditional languages to a large extent through composition of structures and methods without introducing any new features.
- Go language does not provide any special language features for constructors; constructors are just regular functions.
- Go language uses functions with names in the format
newTypeorNewTypeto construct values of a specific type, and whether the first letter is capitalized depends on whether the function needs to be exported for use by other packages. - DMS format (degrees/minutes/seconds) represents positions, not time, where each 60 seconds (") is one minute, and each 60 minutes (') is one degree. For example, the position of Bradbury Landing is represented in DMS format as "South 4°35'22.2", East 137°26'30.1"".