placeDetails method

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

placeDetails The Places API is a service that returns information about places using HTTP requests. Places are defined within this API as establishments, geographic locations, or prominent points of interest.

Parameters:

  • placeId - A textual identifier that uniquely identifies a place, returned from a Place Search. For more information about place IDs, see the place ID overview.
  • 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.
  • sessiontoken - A random string which identifies an autocomplete session for billing purposes. The session begins when the user starts typing a query, and concludes when they select a place and a call to Place Details is made. Each session can have multiple queries, followed by one place selection. The API key(s) used for each request within a session must belong to the same Google Cloud Console project. Once a session has concluded, the token is no longer valid; your app must generate a fresh token for each session. If the sessiontoken parameter is omitted, or if you reuse a session token, the session is charged as if no session token was provided (each request is billed separately). We recommend the following guidelines: - Use session tokens for all autocomplete sessions. - Generate a fresh token for each session. Using a version 4 UUID is recommended. - Ensure that the API key(s) used for all Place Autocomplete and Place Details requests within a session belong to the same Cloud Console project. - Be sure to pass a unique session token for each new session. Using the same token for more than one session will result in each request being billed individually.
  • 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 PlacesDetailsResponse as data Throws DioError if API call or serialization fails

Implementation

Future<Response<PlacesDetailsResponse>> placeDetails({
  required String placeId,
  BuiltList<String>? fields,
  String? sessiontoken,
  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/details/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>{
    r'place_id':
        encodeQueryParameter(_serializers, placeId, const FullType(String)),
    if (fields != null)
      r'fields': encodeCollectionQueryParameter<String>(
        _serializers,
        fields,
        const FullType(BuiltList, [FullType(String)]),
        format: ListFormat.csv,
      ),
    if (sessiontoken != null)
      r'sessiontoken': encodeQueryParameter(
          _serializers, sessiontoken, 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,
  );

  PlacesDetailsResponse _responseData;

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

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