getPhotoBinary method
Get photo binary of a Place.
Required params:
name
orplaceId
andphotoId
: If you opt to useplaceId
andphotoId
, set only the ids without the resource name.maxWidthPx
ormaxHeightPx
: You can specify one or both to set the the maximum desired height and width pixels of the image.
Documentation: https://developers.google.com/maps/documentation/places/web-service/place-photos#get-photo-ref
Implementation
Future<GoogleHTTPResponse<List<int>?>> getPhotoBinary({
/// Photo resource name: https://developers.google.com/maps/documentation/places/web-service/place-photos#photo-name
String? name,
/// Place identifier
String? placeId,
/// Photo identifier
String? photoId,
/// Maximum desired width of the image in pixels: https://developers.google.com/maps/documentation/places/web-service/place-photos#maxheightpx-and-maxwidthpx
int? maxWidthPx,
/// Maximum desired height of the image in pixels: https://developers.google.com/maps/documentation/places/web-service/place-photos#maxheightpx-and-maxwidthpx
int? maxHeightPx,
}) async {
final requestOptions = RequestOptions(
method: 'GET',
baseUrl: _buildPhotoUrl(
name: name,
placeId: placeId,
photoId: photoId,
maxWidthPx: maxWidthPx,
maxHeightPx: maxHeightPx,
skipHttpRedirect: false,
),
responseType: ResponseType.bytes,
receiveTimeout: restAPI.receiveTimeout,
connectTimeout: restAPI.connectTimeout,
sendTimeout: restAPI.sendTimeout,
);
final response = await Dio().fetch<List<int>>(requestOptions);
return GoogleHTTPResponse(
http.Response(
'',
response.statusCode ?? HttpStatus.notFound,
headers: MapUtils.parseHeaders(response.headers) ?? {},
isRedirect: response.isRedirect,
request: http.Request(
response.requestOptions.method,
response.requestOptions.uri,
),
),
response.data,
extraData: response.extra,
error: response.statusCode != 200
? GoogleErrorResponse(
error: ErrorInfo(message: 'Failed to fetch photo binary'),
)
: null,
);
}