findPlaceFromText method

Future<Response<PlacesFindPlaceFromTextResponse>> findPlaceFromText({
  1. required String input,
  2. required String inputtype,
  3. BuiltList<String>? fields,
  4. String? locationbias,
  5. String? language = 'en',
  6. CancelToken? cancelToken,
  7. Map<String, dynamic>? headers,
  8. Map<String, dynamic>? extra,
  9. ValidateStatus? validateStatus,
  10. ProgressCallback? onSendProgress,
  11. ProgressCallback? onReceiveProgress,
})

findPlaceFromText A Find Place request takes a text input and returns a place. The input can be any kind of Places text data, such as a name, address, or phone number. The request must be a string. A Find Place request using non-string data such as a lat/lng coordinate or plus code generates an error. <div class=&quot;note&quot;>Note: If you omit the fields parameter from a Find Place request, only the place_id for the result will be returned.</div>

Parameters:

  • input - Text input that identifies the search target, such as a name, address, or phone number. The input must be a string. Non-string input such as a lat/lng coordinate or plus code generates an error.
  • inputtype - The type of input. This can be one of either textquery or phonenumber. Phone numbers must be in international format (prefixed by a plus sign ("+"), followed by the country code, then the phone number itself). See E.164 ITU recommendation for more information.
  • fields - Use the fields parameter to specify a comma-separated list of place data types to return. For example: fields=formatted_address,name,geometry. Use a forward slash when specifying compound values. For example: opening_hours/open_now. Fields are divided into three billing categories: Basic, Contact, and Atmosphere. Basic fields are billed at base rate, and incur no additional charges. Contact and Atmosphere fields are billed at a higher rate. See the pricing sheet for more information. Attributions, html_attributions, are always returned with every call, regardless of whether the field has been requested. Basic The Basic category includes the following fields: address_component, adr_address, business_status, formatted_address, geometry, icon, icon_mask_base_uri, icon_background_color, name, permanently_closed (deprecated), photo, place_id, plus_code, type, url, utc_offset, vicinity. Contact The Contact category includes the following fields: formatted_phone_number, international_phone_number, opening_hours, website Atmosphere The Atmosphere category includes the following fields: price_level, rating, review, user_ratings_total. <div class="caution">Caution: Place Search requests and Place Details requests do not return the same fields. Place Search requests return a subset of the fields that are returned by Place Details requests. If the field you want is not returned by Place Search, you can use Place Search to get a place_id, then use that Place ID to make a Place Details request.
  • locationbias - Prefer results in a specified area, by specifying either a radius plus lat/lng, or two lat/lng pairs representing the points of a rectangle. If this parameter is not specified, the API uses IP address biasing by default. - IP bias: Instructs the API to use IP address biasing. Pass the string ipbias (this option has no additional parameters). - Point: A single lat/lng coordinate. Use the following format: point:lat,lng. - Circular: A string specifying radius in meters, plus lat/lng in decimal degrees. Use the following format: circle:radius@lat,lng. - Rectangular: A string specifying two lat/lng pairs in decimal degrees, representing the south/west and north/east points of a rectangle. Use the following format:rectangle:south,west|north,east. Note that east/west values are wrapped to the range -180, 180, and north/south values are clamped to the range -90, 90.
  • 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.
  • 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 PlacesFindPlaceFromTextResponse as data Throws DioError if API call or serialization fails

Implementation

Future<Response<PlacesFindPlaceFromTextResponse>> findPlaceFromText({
  required String input,
  required String inputtype,
  BuiltList<String>? fields,
  String? locationbias,
  String? language = 'en',
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  final _path = r'/maps/api/place/findplacefromtext/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 (fields != null)
      r'fields': encodeCollectionQueryParameter<String>(
        _serializers,
        fields,
        const FullType(BuiltList, [FullType(String)]),
        format: ListFormat.csv,
      ),
    r'input':
        encodeQueryParameter(_serializers, input, const FullType(String)),
    r'inputtype':
        encodeQueryParameter(_serializers, inputtype, const FullType(String)),
    if (locationbias != null)
      r'locationbias': encodeQueryParameter(
          _serializers, locationbias, const FullType(String)),
    if (language != null)
      r'language': encodeQueryParameter(
          _serializers, language, const FullType(String)),
  };

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

  PlacesFindPlaceFromTextResponse _responseData;

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

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