buildUrl method

String buildUrl({
  1. String? address,
  2. Bounds? bounds,
  3. String? language,
  4. String? region,
  5. List<Component> components = const [],
  6. List<String> resultType = const [],
  7. List<String> locationType = const [],
  8. String? placeId,
  9. Location? location,
})

Implementation

String buildUrl({
  String? address,
  Bounds? bounds,
  String? language,
  String? region,
  List<Component> components = const [],
  List<String> resultType = const [],
  List<String> locationType = const [],
  String? placeId,
  Location? location,
}) {
  final params = <String, String>{};

  if (location != null) {
    params['latlng'] = location.toString();
  }

  if (placeId != null) {
    params['place_id'] = placeId;
  }

  if (address != null) {
    params['address'] = address;
  }

  if (bounds != null) {
    params['bounds'] = bounds.toString();
  }

  if (language != null) {
    params['language'] = language;
  }

  if (region != null) {
    params['region'] = region;
  }

  if (components.isNotEmpty) {
    params['components'] = components.join('|');
  }

  if (resultType.isNotEmpty) {
    params['result_type'] = resultType.join('|');
  }

  if (locationType.isNotEmpty) {
    params['location_type'] = locationType.join('|');
  }

  if (apiKey != null) {
    params['key'] = apiKey!;
  }

  return url.replace(queryParameters: params).toString();
}