1 | module.exports = function(config) {
|
2 | const googleMapsClient = require('@google/maps').createClient({
|
3 | key: config.GOOGLE_PLACES_KEY,
|
4 | });
|
5 |
|
6 | const google = {};
|
7 |
|
8 | google.places = function(location, type, _radius) {
|
9 | const promise = new Promise(function(resolve, reject) {
|
10 | const parameters = {
|
11 | location: [location.lat, location.lng],
|
12 | type: type,
|
13 | language: 'pt-BR',
|
14 | };
|
15 |
|
16 | googleMapsClient.places(parameters, function(error, response) {
|
17 | if (error) {
|
18 | reject(error);
|
19 | }
|
20 | resolve(response.json.results);
|
21 | });
|
22 | });
|
23 | return promise;
|
24 | };
|
25 |
|
26 | google.buildPhotoUrl = function(reference) {
|
27 | console.log(
|
28 | `https://maps.googleapis.com/maps/api/place/photo?maxwidth=198&maxheight=111&photoreference=${reference}&key=${config.GOOGLE_PLACES_KEY}`,
|
29 | );
|
30 | return `https://maps.googleapis.com/maps/api/place/photo?maxwidth=198&maxheight=111&photoreference=${reference}&key=${config.GOOGLE_PLACES_KEY}`;
|
31 | };
|
32 |
|
33 | return google;
|
34 | };
|