GeoPos.fromResult constructor

GeoPos.fromResult(
  1. List<RespType>? result
)

Implementation

factory GeoPos.fromResult(List<RespType<dynamic>>? result) {
  var _positions = <GeoPoint>[];

  if (result != null) {
    for (var item in result) {
      if (item is RespArray) {
        final coords = item.payload;
        if (coords != null && coords.length == 2) {
          final longitudeItem = coords[0] as RespBulkString;
          final latitudeItem = coords[1] as RespBulkString;

          if (longitudeItem.payload != null && latitudeItem.payload != null) {
            final longitude = double.parse(longitudeItem.payload!);
            final latitude = double.parse(latitudeItem.payload!);
            _positions
                .add(GeoPoint(longitude: longitude, latitude: latitude));
          }
        }
      }
    }
  }

  return GeoPos(positions: _positions);
}