// @flow const apiKey = 'AIzaSyBfMm1y6JayCbXrQmgAG1R3ka4ZOJno_5E'; const placesUrl = `https://maps.googleapis.com/maps/api/place/details/json?key=${apiKey}`; const photosUrl = `https://maps.googleapis.com/maps/api/place/photo?key=${apiKey}`; export const getPlaceDetails = async (placeid: ?string) => { if (!placeid || typeof placeid !== 'string') { throw new Error('placeid looks wrong'); } const res = await fetch(`${placesUrl}&placeid=${placeid}`); const { error_message, result } = await res.json(); if (error_message) { throw new Error(error_message); } return result; }; export const getURLForPhotoReference = (opts?: { maxheight?: number, maxwidth?: number } = {}) => ( photoReference: string ) => { if (!photoReference) { return ''; } const { maxheight, maxwidth } = opts; const maxHeight = `&maxheight=${maxheight || 600}`; const maxWidth = maxwidth ? `&maxwidth=${maxwidth}` : ''; const photoref = `&photoreference=${photoReference}`; return `${photosUrl}${photoref}${maxHeight}${maxWidth}`; };