convertCoordinates function

Position convertCoordinates(
  1. Position coord,
  2. CoordinateSystem fromSystem,
  3. CoordinateSystem toSystem
)

Converts coordinates from one system to another.

Valid systems: CoordinateSystem.wgs84, CoordinateSystem.mercator Returns: Position in the target system

Implementation

Position convertCoordinates(
    Position coord, CoordinateSystem fromSystem, CoordinateSystem toSystem) {
  if (fromSystem == toSystem) {
    return coord;
  }

  if (fromSystem == CoordinateSystem.wgs84 &&
      toSystem == CoordinateSystem.mercator) {
    return toMercator(coord);
  } else if (fromSystem == CoordinateSystem.mercator &&
      toSystem == CoordinateSystem.wgs84) {
    return toWGS84(coord);
  } else {
    throw ArgumentError(
        "Unsupported coordinate system conversion from ${fromSystem.runtimeType} to ${toSystem.runtimeType}");
  }
}