textSearch method

Future<Response<PlacesTextSearchResponse>> textSearch({
  1. required String query,
  2. String? location,
  3. String? maxprice,
  4. String? minprice,
  5. bool? opennow,
  6. String? pagetoken,
  7. num? radius,
  8. String? type,
  9. String? language = 'en',
  10. String? region = 'en',
  11. CancelToken? cancelToken,
  12. Map<String, dynamic>? headers,
  13. Map<String, dynamic>? extra,
  14. ValidateStatus? validateStatus,
  15. ProgressCallback? onSendProgress,
  16. ProgressCallback? onReceiveProgress,
})

textSearch The Google Places API Text Search Service is a web service that returns information about a set of places based on a string — for example &quot;pizza in New York&quot; or &quot;shoe stores near Ottawa&quot; or &quot;123 Main Street&quot;. The service responds with a list of places matching the text string and any location bias that has been set. The service is especially useful for making ambiguous address queries in an automated system, and non-address components of the string may match businesses as well as addresses. Examples of ambiguous address queries are incomplete addresses, poorly formatted addresses, or a request that includes non-address components such as business names. The search response will include a list of places. You can send a Place Details request for more information about any of the places in the response.

Parameters:

  • query - The text string on which to search, for example: "restaurant" or "123 Main Street". The Google Places service will return candidate matches based on this string and order the results based on their perceived relevance.
  • location - The point around which to retrieve place information. This must be specified as latitude,longitude. <div class="note">The location parameter may be overriden if the query contains an explicit location such as Market in Barcelona. Using quotes around the query may also influence the weight given to the location and radius.
  • maxprice - Restricts results to only those places within the specified range. Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. The exact amount indicated by a specific value will vary from region to region.
  • minprice - Restricts results to only those places within the specified range. Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. The exact amount indicated by a specific value will vary from region to region.
  • opennow - Returns only those places that are open for business at the time the query is sent. Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
  • pagetoken - Returns up to 20 results from a previously run search. Setting a pagetoken parameter will execute a search with the same parameters used previously — all parameters other than pagetoken will be ignored.
  • radius - Defines the distance (in meters) within which to return place results. You may bias results to a specified circle by passing a location and a radius parameter. Doing so instructs the Places service to prefer showing results within that circle; results outside of the defined area may still be displayed. The radius will automatically be clamped to a maximum value depending on the type of search and other parameters. * Autocomplete: 50,000 meters * Nearby Search: * with keyword or name: 50,000 meters * without keyword or name * rankby=prominence (default): 50,000 meters * rankby=distance: A few kilometers depending on density of area * Query Autocomplete: 50,000 meters * Text Search: 50,000 meters
  • type - Restricts the results to places matching the specified type. Only one type may be specified. If more than one type is provided, all types following the first entry are ignored. * type=hospital|pharmacy|doctor becomes type=hospital * type=hospital,pharmacy,doctor is ignored entirely See the list of supported types. <div class="note">Note: Adding both keyword and type with the same value (keyword=cafe&type=cafe or keyword=parking&type=parking) can yield ZERO_RESULTS.
  • language - The language in which to return results. * See the list of supported languages. Google often updates the supported languages, so this list may not be exhaustive. * If language is not supplied, the API attempts to use the preferred language as specified in the Accept-Language header. * The API does its best to provide a street address that is readable for both the user and locals. To achieve that goal, it returns street addresses in the local language, transliterated to a script readable by the user if necessary, observing the preferred language. All other addresses are returned in the preferred language. Address components are all returned in the same language, which is chosen from the first component. * If a name is not available in the preferred language, the API uses the closest match. * The preferred language has a small influence on the set of results that the API chooses to return, and the order in which they are returned. The geocoder interprets abbreviations differently depending on language, such as the abbreviations for street types, or synonyms that may be valid in one language but not in another. For example, utca and tér are synonyms for street in Hungarian.
  • region - The region code, specified as a ccTLD ("top-level domain") two-character value. Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland").
  • cancelToken - A CancelToken that can be used to cancel the operation
  • headers - Can be used to add additional headers to the request
  • extras - Can be used to add flags to the request
  • validateStatus - A ValidateStatus callback that can be used to determine request success based on the HTTP status of the response
  • onSendProgress - A ProgressCallback that can be used to get the send progress
  • onReceiveProgress - A ProgressCallback that can be used to get the receive progress

Returns a Future containing a Response with a PlacesTextSearchResponse as data Throws DioError if API call or serialization fails

Implementation

Future<Response<PlacesTextSearchResponse>> textSearch({
  required String query,
  String? location,
  String? maxprice,
  String? minprice,
  bool? opennow,
  String? pagetoken,
  num? radius,
  String? type,
  String? language = 'en',
  String? region = 'en',
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  final _path = r'/maps/api/place/textsearch/json';
  final _options = Options(
    method: r'GET',
    headers: <String, dynamic>{
      ...?headers,
    },
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[
        {
          'type': 'apiKey',
          'name': 'ApiKeyAuth',
          'keyName': 'key',
          'where': 'query',
        },
      ],
      ...?extra,
    },
    validateStatus: validateStatus,
  );

  final _queryParameters = <String, dynamic>{
    if (location != null)
      r'location': encodeQueryParameter(
          _serializers, location, const FullType(String)),
    if (maxprice != null)
      r'maxprice': encodeQueryParameter(
          _serializers, maxprice, const FullType(String)),
    if (minprice != null)
      r'minprice': encodeQueryParameter(
          _serializers, minprice, const FullType(String)),
    if (opennow != null)
      r'opennow':
          encodeQueryParameter(_serializers, opennow, const FullType(bool)),
    if (pagetoken != null)
      r'pagetoken': encodeQueryParameter(
          _serializers, pagetoken, const FullType(String)),
    r'query':
        encodeQueryParameter(_serializers, query, const FullType(String)),
    if (radius != null)
      r'radius':
          encodeQueryParameter(_serializers, radius, const FullType(num)),
    if (type != null)
      r'type':
          encodeQueryParameter(_serializers, type, const FullType(String)),
    if (language != null)
      r'language': encodeQueryParameter(
          _serializers, language, const FullType(String)),
    if (region != null)
      r'region':
          encodeQueryParameter(_serializers, region, const FullType(String)),
  };

  final _response = await _dio.request<Object>(
    _path,
    options: _options,
    queryParameters: _queryParameters,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  PlacesTextSearchResponse _responseData;

  try {
    const _responseType = FullType(PlacesTextSearchResponse);
    _responseData = _serializers.deserialize(
      _response.data!,
      specifiedType: _responseType,
    ) as PlacesTextSearchResponse;
  } catch (error, stackTrace) {
    throw DioError(
      requestOptions: _response.requestOptions,
      response: _response,
      type: DioErrorType.other,
      error: error,
    )..stackTrace = stackTrace;
  }

  return Response<PlacesTextSearchResponse>(
    data: _responseData,
    headers: _response.headers,
    isRedirect: _response.isRedirect,
    requestOptions: _response.requestOptions,
    redirects: _response.redirects,
    statusCode: _response.statusCode,
    statusMessage: _response.statusMessage,
    extra: _response.extra,
  );
}