๐ 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
๐ Related Abstractionsโ
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โ
| Property | Description |
|---|---|
PlaceId | Unique identifier of the place |
Text | Full suggestion text |
EndOffset | Index where the match ends (useful for highlighting) |
Types | Associated 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โ
| Property | Description |
|---|---|
Input | Partial user input (e.g., "coffee", "pizza near") |
LocationBias | Optional 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 inputWithLocationBias(...)โ optional, geographic bias that influences ranking
โก Exampleโ
var request = new AutocompleteRequestBuilder()
.WithInput("pizza")
.WithLocationBias(1000, 40.7128, -74.0060)
.Build();
โ ๏ธ Validationโ
- Throws MapsInvalidRequestException if:
- Input is null, empty, or whitespace
- Build is called without setting input
๐ง Notesโ
- Enforces valid request construction
- Improves readability with fluent API
- Prevents invalid states