Convert lat,lon for WGS84 ellipsoid to MGRS string.
| 435 | |
| 436 | // Convert lat,lon for WGS84 ellipsoid to MGRS string. |
| 437 | std::string FormatMGRS(double lat, double lon, int precision) |
| 438 | { |
| 439 | if (precision > 5) |
| 440 | precision = 5; |
| 441 | else if (precision < 1) |
| 442 | precision = 1; |
| 443 | |
| 444 | if (lat <= -80 || lat > 84) |
| 445 | return {}; // Latitude limit exceeded. |
| 446 | if (lon <= -180 || lon > 180) |
| 447 | return {}; // Longitude limit exceeded. |
| 448 | |
| 449 | UTMPoint mgrsp = LatLonToUtm(lat, lon); |
| 450 | |
| 451 | // Need to set the right letter for the latitude. |
| 452 | auto const zoneLetter = LatitudeToZoneLetter(lat); |
| 453 | ASSERT(zoneLetter, (lat)); |
| 454 | mgrsp.zoneLetter = zoneLetter; |
| 455 | return UTMtoMgrsStr(mgrsp, precision); |
| 456 | } |
| 457 | |
| 458 | // Convert lat,lon for WGS84 ellipsoid to UTM string. |
| 459 | std::string FormatUTM(double lat, double lon) |