kb0 / maps_toolkit

Dart library for area, distance, heading measurements
Apache License 2.0
46 stars 17 forks source link

Getting the corners of a square gives mixed results #12

Open kaciula opened 3 years ago

kaciula commented 3 years ago

Hi.

I am trying to draw several square polygons on Google Maps and I am getting mixed results. For some coordinates it's drawing a perfect square and for others it's clearly a rectangle. I'm just computing the 4 corners and passing them to Google Maps to draw the polygons. What could be the cause? Am I missing something? The coordinates are very close together in the same neighbourhood in Bucharest, Romania.

List<sp.LatLng> getMiniSquarePolygon(int position) {
    const double latLen = 1; // metres
    final sp.LatLng topLeftCorner = <INITIAL COORDINATES>;
    final sp.LatLng topRightCorner = sp.SphericalUtil.computeOffset(
        topLeftCorner, latLen / cos(topLeftCorner.latitude), 90);
    final sp.LatLng bottomRightCorner =
        sp.SphericalUtil.computeOffset(topRightCorner, latLen, 180);
    final sp.LatLng bottomLeftCorner = sp.SphericalUtil.computeOffset(
        bottomRightCorner, latLen / cos(bottomRightCorner.latitude), 270);
    return <LatLng>[
      topLeftCorner,
      topRightCorner,
      bottomRightCorner,
      bottomLeftCorner,
      topLeftCorner,
    ];
  }

flutter_3