π Search
The Search feature allows you to find places using either:
- Text queries (e.g., "restaurants near me")
- Geographic constraints (nearby search)
π Related Abstractionsβ
This feature is exposed through:
π See: ISearchService
π§© Serviceβ
public interface ISearchService {
Task<IReadOnlyList<PlaceSearchResult>> SearchByTextAsync(string textQuery);
Task<IReadOnlyList<PlaceSearchResult>> SearchByNearbyAsync(NearbyRequest nearbyRequest);
}
βοΈ Methodsβ
- SearchByTextAsync β search using a text query
- SearchByNearbyAsync β search using location
π§ Notesβ
- Text search is quick and flexible
- Nearby search gives more control and precision
- Use nearby search when location matters (maps, GPS, etc.)
β‘ Examplesβ
β¨οΈ Text Searchβ
var results = await searchService.SearchByTextAsync("coffee near Medellin");
πΊοΈ Nearby Searchβ
var request = new NearbyRequestBuilder()
.WithTypes(["restaurant"])
.WithLocationRestriction(500, 40.7128, -74.0060)
.WithMaxResults(5)
.Build();
var results = await places.Search.SearchByNearbyAsync(request);
π¦ Modelsβ
PlaceSearchResultβ
Represents a place returned from a search query.
public sealed class PlaceSearchResult {
public string? PlaceId { get; internal set; }
public string? DisplayName { get; internal set; }
public IReadOnlyList<string> Types { get; internal set; } = [];
}
βοΈ Propertiesβ
| Property | Description |
|---|---|
PlaceId | Unique identifier of the place |
DisplayName | Name of the place |
Types | Associated place types |
π‘ Use IDetailsService if you need richer information.
π§Ύ Requestβ
NearbyRequestβ
Represents a request for retrieving place suggestions.
public sealed class NearbyRequest {
public IReadOnlyList<string> IncludedTypes { get; internal set; } = [];
public int MaxResultCount { get; internal set; } = 1;
public LocationRestriction LocationRestriction { get; internal set; } = new();
}
βοΈ Propertiesβ
| Property | Description |
|---|---|
IncludedTypes | List of place types to include in the search |
MaxResultCount | Maximum number of results to return |
LocationRestriction | Geographic restriction applied to the search |
π§ Notesβ
- Must be constructed using
NearbyRequestBuilder
NearbyRequestBuilderβ
Provides a fluent API for constructing nearby search requests.
public sealed class NearbyRequestBuilder {
public NearbyRequestBuilder WithTypes(IEnumerable<string> includedTypes);
public NearbyRequestBuilder WithMaxResults(int maxResults);
public NearbyRequestBuilder WithLocationRestriction(
double radius, double latitude, double longitude
);
public NearbyRequest Build();
}
βοΈ Configurationβ
WithTypes(...)β required, defines place types (e.g., restaurant, cafe)WithMaxResults(...)β optional, limits number of resultsWithLocationRestriction(...)β required, defines search area
β οΈ Validationβ
- Types must be provided
- Location restriction must be defined
- Max results must be greater than 0