searchNearby method

  1. @override
Future<SearchNearbyResponse> searchNearby({
  1. required List<PlaceField> fields,
  2. required CircularBounds locationRestriction,
  3. List<String>? includedTypes,
  4. List<String>? includedPrimaryTypes,
  5. List<String>? excludedTypes,
  6. List<String>? excludedPrimaryTypes,
  7. NearbySearchRankPreference? rankPreference,
  8. String? regionCode,
  9. 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);
}