getPlainPhotoUrl method
Get the photo url of a Place after redirect, this means the final photo url will not use the apiKey nor the place or photo id.
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<String>> getPlainPhotoUrl({
/// 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: true,
),
responseType: ResponseType.json,
receiveTimeout: restAPI.receiveTimeout,
connectTimeout: restAPI.connectTimeout,
sendTimeout: restAPI.sendTimeout,
);
final response = await Dio().fetch<Map<String, dynamic>>(requestOptions);
late Photo? photo =
response.data == null ? null : Photo.fromJson(response.data!);
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,
),
),
photo?.photoUri,
extraData: response.extra,
error: response.statusCode != 200
? GoogleErrorResponse(
error: ErrorInfo(message: 'Failed to fetch photo binary'),
)
: null,
);
}