travopti/backend/models/getPlaceNearby.js
2020-07-10 15:35:38 +02:00

21 lines
791 B
JavaScript

const axios = require("axios")
const getPlacePhoto = require("./getPlacePhoto.js")
const radius = 20000 // Search radius in meters
const rankby = "prominence" // Sorting of results
const types = "tourist_attraction" // Category which shall be searched
module.exports = async (lat, lng) => {
const res = await axios.get(
`https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${lat},${lng}&radius=${radius}&type=${types}&rankby=${rankby}&key=${process.env.GOOGLE_CLOUD_APIS}`
);
// Photo url is not returned by default since it overuses Google Place API
/*
for (let result of res.data.results) {
for (let photo of result.photos) {
photo.url = await getPlacePhoto(photo.photo_reference)
}
}*/
return res.data
}