Skip to content

Commit 73cf4c0

Browse files
committed
google_maps_platform init
1 parent e7dd5ab commit 73cf4c0

File tree

4 files changed

+287
-1
lines changed

4 files changed

+287
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import google_maps_platform from "../../google_maps_platform.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "google_maps_platform-get-place-details",
6+
name: "Get Place Details",
7+
description: "Retrieves detailed information for a specific place using its Place ID. [See the documentation](https://developers.google.com/maps/documentation/places/web-service/place-details)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
google_maps_platform,
12+
placeId: {
13+
propDefinition: [
14+
google_maps_platform,
15+
"placeId",
16+
],
17+
},
18+
fields: {
19+
propDefinition: [
20+
google_maps_platform,
21+
"fields",
22+
],
23+
optional: true,
24+
},
25+
},
26+
async run({ $ }) {
27+
const response = await this.google_maps_platform.getPlaceDetails({
28+
placeId: this.placeId,
29+
fields: this.fields,
30+
});
31+
32+
$.export("$summary", `Retrieved details for Place ID ${this.placeId}`);
33+
return response;
34+
},
35+
};
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import google_maps_platform from "../../google_maps_platform.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "google_maps_platform-search-places",
6+
name: "Search Places",
7+
description: "Searches for places based on location, radius, and optional filters like keywords, place type, or name. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
google_maps_platform,
12+
locationLatitude: {
13+
propDefinition: [
14+
google_maps_platform,
15+
"locationLatitude",
16+
],
17+
},
18+
locationLongitude: {
19+
propDefinition: [
20+
google_maps_platform,
21+
"locationLongitude",
22+
],
23+
},
24+
radius: {
25+
propDefinition: [
26+
google_maps_platform,
27+
"radius",
28+
],
29+
},
30+
keywords: {
31+
propDefinition: [
32+
google_maps_platform,
33+
"keywords",
34+
],
35+
optional: true,
36+
},
37+
placeType: {
38+
propDefinition: [
39+
google_maps_platform,
40+
"placeType",
41+
],
42+
optional: true,
43+
},
44+
name: {
45+
propDefinition: [
46+
google_maps_platform,
47+
"name",
48+
],
49+
optional: true,
50+
},
51+
},
52+
async run({ $ }) {
53+
const params = {
54+
location: `${this.locationLatitude},${this.locationLongitude}`,
55+
};
56+
57+
if (this.radius) {
58+
params.radius = this.radius;
59+
}
60+
61+
if (this.keywords) {
62+
params.keyword = this.keywords;
63+
}
64+
65+
if (this.placeType) {
66+
params.type = this.placeType;
67+
}
68+
69+
if (this.name) {
70+
params.name = this.name;
71+
}
72+
73+
const response = await this.google_maps_platform.searchPlaces({
74+
params,
75+
});
76+
77+
const placeCount = response.results.length;
78+
$.export("$summary", `Found ${placeCount} place(s) near (${this.locationLatitude}, ${this.locationLongitude})`);
79+
80+
return response;
81+
},
82+
};

components/google_maps_platform/app/google_maps_platform.app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export default defineApp({
1010
console.log(Object.keys(this.$auth));
1111
},
1212
},
13-
});
13+
});
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "google_places",
6+
version: "0.0.{{ts}}",
7+
propDefinitions: {
8+
// Required props for searching places
9+
locationLatitude: {
10+
type: "number",
11+
label: "Latitude",
12+
description: "The latitude of the location to search around.",
13+
},
14+
locationLongitude: {
15+
type: "number",
16+
label: "Longitude",
17+
description: "The longitude of the location to search around.",
18+
},
19+
// Optional props for searching places
20+
radius: {
21+
type: "integer",
22+
label: "Radius (meters)",
23+
description: "The radius in meters within which to search for places.",
24+
optional: true,
25+
},
26+
keywords: {
27+
type: "string",
28+
label: "Keywords",
29+
description: "A term to be matched against all content that Google has indexed for this place.",
30+
optional: true,
31+
},
32+
placeType: {
33+
type: "string",
34+
label: "Place Type",
35+
description: "Restricts the results to places matching the specified type.",
36+
optional: true,
37+
async options() {
38+
return [
39+
{
40+
label: "Restaurant",
41+
value: "restaurant",
42+
},
43+
{
44+
label: "Cafe",
45+
value: "cafe",
46+
},
47+
{
48+
label: "Bar",
49+
value: "bar",
50+
},
51+
{
52+
label: "Library",
53+
value: "library",
54+
},
55+
{
56+
label: "Park",
57+
value: "park",
58+
},
59+
// Add more place types as needed
60+
];
61+
},
62+
},
63+
name: {
64+
type: "string",
65+
label: "Name",
66+
description: "The name of the place to search for.",
67+
optional: true,
68+
},
69+
// Required props for retrieving place details
70+
placeId: {
71+
type: "string",
72+
label: "Place ID",
73+
description: "The unique identifier of the place to retrieve details for.",
74+
},
75+
fields: {
76+
type: "string[]",
77+
label: "Fields",
78+
description: "Specific fields to include in the place details response.",
79+
optional: true,
80+
options: [
81+
{
82+
label: "Address",
83+
value: "formatted_address",
84+
},
85+
{
86+
label: "Reviews",
87+
value: "reviews",
88+
},
89+
{
90+
label: "Hours",
91+
value: "current_opening_hours",
92+
},
93+
{
94+
label: "Phone Number",
95+
value: "international_phone_number",
96+
},
97+
{
98+
label: "Website",
99+
value: "website",
100+
},
101+
// Add more fields as needed
102+
],
103+
},
104+
},
105+
methods: {
106+
_baseUrl() {
107+
return "https://maps.googleapis.com/maps/api/place";
108+
},
109+
async _makeRequest(opts = {}) {
110+
const {
111+
$ = this, method = "GET", path = "/", headers, ...otherOpts
112+
} = opts;
113+
return axios($, {
114+
...otherOpts,
115+
method,
116+
url: this._baseUrl() + path,
117+
headers: {
118+
...headers,
119+
"Content-Type": "application/json",
120+
},
121+
params: {
122+
key: this.$auth.api_key,
123+
...otherOpts.params,
124+
},
125+
});
126+
},
127+
async searchPlaces(opts = {}) {
128+
return this._makeRequest({
129+
method: "GET",
130+
path: "/nearbysearch/json",
131+
...opts,
132+
});
133+
},
134+
async getPlaceDetails(opts = {}) {
135+
const {
136+
placeId, fields, ...otherOpts
137+
} = opts;
138+
const params = {};
139+
if (fields && fields.length > 0) {
140+
params.fields = fields.join(",");
141+
}
142+
return this._makeRequest({
143+
method: "GET",
144+
path: "/details/json",
145+
params: params,
146+
...otherOpts,
147+
});
148+
},
149+
async paginate(fn, ...opts) {
150+
let results = [];
151+
let nextPageToken = null;
152+
153+
do {
154+
const response = await fn({
155+
...opts,
156+
pageToken: nextPageToken,
157+
});
158+
results = results.concat(response.results);
159+
nextPageToken = response.next_page_token;
160+
if (nextPageToken) {
161+
// Google Places API requires a short delay before using the nextPageToken
162+
await new Promise((resolve) => setTimeout(resolve, 2000));
163+
}
164+
} while (nextPageToken);
165+
166+
return results;
167+
},
168+
},
169+
};

0 commit comments

Comments
 (0)