Pannam T
Pannam T

Reputation: 479

How can I use the value obtained from a map in a function

I am trying to get some values from this function getBox which returns me east, west, north and south

 getBox(lat, long) {
    double north;
    double south;
    double east;
    double west;
    //calculate the offset of 1km at a certain coordinate
    var dist = kmInDegree(lat, long);
    //calculate the bounds and make an object of them
    var bounds = {
      north: lat + dist.lat,
      south: lat - dist.lat,
      east: long + dist.long,
      west: long - dist.long
    };
    return bounds;
  }

I then want to use this returned value-form map below bound. east, bound.north etc. How could I do it ?

controller.Shape(BoundingBox( east: "use value here" , north:"use value here" , south:"use value here" , west:"use value here" ,));

Upvotes: 0

Views: 40

Answers (1)

enzo
enzo

Reputation: 11496

You can use enums:

enum Direction { north, south, east, west }

Map<Direction, double> getBox(lat, long) {
  var dist = kmInDegree(lat, long);
  return {
    Direction.north: lat + dist.lat,
    Direction.south: lat - dist.lat,
    Direction.east: long + dist.long,
    Direction.west: long - dist.long
  };
}

// ...

final Map<Direction, double> box = getBox(...);
controller.Shape(BoundingBox(
  east: box[Direction.east],
  north: box[Direction.north],
  south: box[Direction.south],
  west: box[Direction.west]));

or return a BoundingBox itself:

BoundingBox getBox(lat, long) {
  var dist = kmInDegree(lat, long);
  return BoundingBox(
    north: lat + dist.lat,
    south: lat - dist.lat,
    east: long + dist.long,
    west: long - dist.long
  );
}

// ...

final BoundingBox box = getBox(...);
controller.Shape(box);

Upvotes: 2

Related Questions