Skip to main content

๐Ÿ”Ž Autocomplete

The Autocomplete feature provides real-time place suggestions based on partial user input.

It is commonly used to power:

  • Search bars
  • Location inputs
  • Address forms

This feature is exposed through:

๐Ÿ‘‰ IAutocompleteService


๐Ÿงฉ Serviceโ€‹

public interface IAutocompleteService {
Task<IReadOnlyList<PlaceSuggestion>> SuggestPlacesAsync(
AutocompleteRequest autocompleteRequest
);
}

โš™๏ธ Methodsโ€‹

  • SuggestPlacesAsync โ†’ suggest possible places according to user text input and geograpich bias

โšก Exampleโ€‹

var request = new AutocompleteRequestBuilder()
.WithInput("coffee")
.Build();

var suggestions = await autocompleteService.SuggestPlacesAsync(request);

๐Ÿ“ฆ Modelsโ€‹

PlaceSuggestionโ€‹

Represents a predicted place returned from an autocomplete query.

public sealed class PlaceSuggestion {
public string PlaceId { get; internal set; } = null!;
public string Text { get; internal set; } = null!;
public int EndOffset { get; internal set; } = -1;
public IReadOnlyList<string> Types { get; internal set; } = [];
}

โš™๏ธ Propertiesโ€‹

PropertyDescription
PlaceIdUnique identifier of the place
TextFull suggestion text
EndOffsetIndex where the match ends (useful for highlighting)
TypesAssociated place types

๐Ÿง  Notesโ€‹

  • Lightweight model optimized for UI scenarios
  • Typically used before fetching full place details

๐Ÿงพ Requestโ€‹

AutocompleteRequestโ€‹

Represents a request for retrieving place suggestions.

public sealed class AutocompleteRequest {
public string Input { get; internal set; } = null!;
public LocationBias? LocationBias { get; internal set; }
}

โš™๏ธ Propertiesโ€‹

PropertyDescription
InputPartial user input (e.g., "coffee", "pizza near")
LocationBiasOptional geographic bias for results

๐Ÿง  Notesโ€‹

  • Must be constructed using AutocompleteRequestBuilder
  • Location bias influences ranking but does not strictly filter results

AutocompleteRequestBuilderโ€‹

Provides a fluent API to construct AutocompleteRequest.

public sealed class AutocompleteRequestBuilder {
public AutocompleteRequestBuilder WithInput(string input);
public AutocompleteRequestBuilder WithLocationBias(double radius, double latitude, double longitude);

public AutocompleteRequest Build();
}

โš™๏ธ Configurationโ€‹

  • WithInput(...) โ†’ required, partial user input
  • WithLocationBias(...) โ†’ optional, geographic bias that influences ranking

โšก Exampleโ€‹

var request = new AutocompleteRequestBuilder()
.WithInput("pizza")
.WithLocationBias(1000, 40.7128, -74.0060)
.Build();

โš ๏ธ Validationโ€‹

๐Ÿง  Notesโ€‹

  • Enforces valid request construction
  • Improves readability with fluent API
  • Prevents invalid states