2017-07-22 16:28:05 -05:00
|
|
|
// @flow
|
|
|
|
|
const apiKey = 'AIzaSyBfMm1y6JayCbXrQmgAG1R3ka4ZOJno_5E';
|
|
|
|
|
const placesUrl = `https://maps.googleapis.com/maps/api/place/details/json?key=${apiKey}`;
|
2017-07-23 19:58:10 -05:00
|
|
|
const photosUrl = `https://maps.googleapis.com/maps/api/place/photo?key=${apiKey}`;
|
2017-07-22 16:28:05 -05:00
|
|
|
|
2017-07-23 19:58:10 -05:00
|
|
|
export const getPlaceDetails = async (placeid: ?string) => {
|
2017-07-22 16:28:05 -05:00
|
|
|
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;
|
|
|
|
|
};
|
2017-07-23 19:58:10 -05:00
|
|
|
|
|
|
|
|
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}`;
|
|
|
|
|
};
|