searchNearby method
Future<SearchNearbyResponse>
searchNearby({
- required List<
PlaceField> fields, - required CircularBounds locationRestriction,
- List<
String> ? includedTypes, - List<
String> ? includedPrimaryTypes, - List<
String> ? excludedTypes, - List<
String> ? excludedPrimaryTypes, - NearbySearchRankPreference? rankPreference,
- String? regionCode,
- int? maxResultCount,
override
Search for place(s) of interest using a location.
Only the requested fields will be returned. If none specified,
all fields will be returned.
Note that different fields can incur different billing.
For more info on nearby search: https://developers.google.com/maps/documentation/places/android-sdk/nearby-search
Implementation
@override
Future<inter.SearchNearbyResponse> searchNearby({
required List<inter.PlaceField> fields,
required inter.CircularBounds locationRestriction,
List<String>? includedTypes,
List<String>? includedPrimaryTypes,
List<String>? excludedTypes,
List<String>? excludedPrimaryTypes,
inter.NearbySearchRankPreference? rankPreference,
String? regionCode,
int? maxResultCount,
}) async {
final restriction =
core.CircleLiteral(
center: core.LatLngLiteral(
lat: locationRestriction.center.lat,
lng: locationRestriction.center.lng,
),
radius: locationRestriction.radius,
)
as JSAny;
final request = SearchNearbyRequest(
locationRestriction: restriction,
fields: _mapFields(fields),
includedTypes: includedTypes?.map((s) => s.toJS).toList().toJS,
includedPrimaryTypes: includedPrimaryTypes
?.map((s) => s.toJS)
.toList()
.toJS,
excludedTypes: excludedTypes?.map((s) => s.toJS).toList().toJS,
excludedPrimaryTypes: excludedPrimaryTypes
?.map((s) => s.toJS)
.toList()
.toJS,
rankPreference: _mapNearbyRankPreference(rankPreference),
region: regionCode,
language: _language,
maxResultCount: maxResultCount,
);
final prom = places.Place.searchNearby(request) as JSPromise<JSObject>?;
final result = await prom?.toDart;
final response = result as ext.SearchPlacesResponse?;
final resultPlaces =
response?.places.map(_parsePlace).nonNulls.toList(growable: false) ??
[];
return inter.SearchNearbyResponse(resultPlaces);
}