-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtransporters-api.js
More file actions
54 lines (47 loc) · 1.66 KB
/
transporters-api.js
File metadata and controls
54 lines (47 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { Client, Status } = require("@googlemaps/google-maps-services-js");
/* eslint-disable no-console */
/* eslint-disable class-methods-use-this */
/* eslint-disable no-undef */
/* eslint-disable no-unused-vars */
const https = require("https");
// Option parameter for google api request
const options = {
hostname: "maps.googleapis.com",
port: 443,
path: `/maps/api/place/textsearch/json?query=transport&location=${this.latitude},${this.longitude}&radius=10000&key=AIzaSyAm00Wsdh6jJB2QzlW5c6t_nu0gMRAZB9s`,
method: "GET"
};
const client = new Client({});
// Allow function to receive coordinate argument from client
class GetTripInfo {
constructor(latitude, longitude, method) {
this.latitude = latitude;
this.longitude = longitude;
this.method = method;
}
// api to list all the transporters within 1km of users location
async getPlaces() {
let aa = {};
try {
const r = await client.textSearch({
params: {
locations: [{ lat: this.latitude, lng: this.longitude }],
query: this.method,
key: process.env.TEST_KEY,
radius: 10000
}
});
if (r.data.status === Status.OK) {
aa = r.data.results;
} else {
aa = r.data.error_message;
}
} catch (e) {
// console.log(e);
}
return aa;
}
}
module.exports = GetTripInfo;
// path: `/maps/api/place/textsearch/json?query=transport&location=${this.latitude},${this.longitude}&radius=10000&key=AIzaSyDg-6GC6doxzpE_etI9E-yJR2NOLyFzBYc`,
// path: `/maps/api/place/textsearch/json?query=transport&location=${this.latitude},${this.longitude}&radius=10000&key=AIzaSyC8G-WQhDTvlVflIFPzOj30rDQGk0Fekx8`,