{"id":20629186,"url":"https://github.com/dcts/dcts-google-places-api","last_synced_at":"2025-03-08T17:21:16.536Z","repository":{"id":40794357,"uuid":"248050638","full_name":"dcts/dcts-google-places-api","owner":"dcts","description":"Node client for Google Places API (placeSearch, placeDetails, placePhoto). Published as NPM package.","archived":false,"fork":false,"pushed_at":"2023-03-04T06:53:28.000Z","size":500,"stargazers_count":0,"open_issues_count":14,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T11:13:15.735Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/dcts-google-places-api","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-17T19:00:16.000Z","updated_at":"2022-06-23T13:24:38.000Z","dependencies_parsed_at":"2024-11-16T13:42:10.361Z","dependency_job_id":"db0c9fdf-f8bb-4040-9db0-e0ebc577cb9e","html_url":"https://github.com/dcts/dcts-google-places-api","commit_stats":{"total_commits":14,"total_committers":3,"mean_commits":4.666666666666667,"dds":0.1428571428571429,"last_synced_commit":"17b0f771a558f1582edce1694a0fc0a6bd5d0441"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcts%2Fdcts-google-places-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcts%2Fdcts-google-places-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcts%2Fdcts-google-places-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcts%2Fdcts-google-places-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcts","download_url":"https://codeload.github.com/dcts/dcts-google-places-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242582608,"owners_count":20153279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T13:42:02.376Z","updated_at":"2025-03-08T17:21:16.513Z","avatar_url":"https://github.com/dcts.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Google Places API (for node)\nNode client to run the basic google places API requests (using axios). Published on [NPM](https://www.npmjs.com/package/dcts-google-places-api).\n- [**Place Search**](https://developers.google.com/places/web-service/search)\n- [**Place Details**](https://developers.google.com/places/web-service/details)\n- [**Place Photos**](https://developers.google.com/places/web-service/photos)\n\n\n## Installing\n```bash\n$ npm install dcts-google-places-api\n```\n\n## Examples\n### Initialzation\n```js\nconst apiKey = \"INSERT_YOUR_API_KEY\"; // define API key\nconst GooglePlacesApi = require('dcts-google-places-api');\nconst googleapi = new GooglePlacesApi(apiKey); // initialize\n```\n### Place Search\n```js\nconst searchQuery = \"Pizza New York\"; // example search\n\n// with promises\ngoogleapi.runPlaceSearch(searchQuery).then(placeId =\u003e {\n  console.log(placeId); // returns placeId (as string) or null\n});\n\n// with async await\n(async () =\u003e {\n  let placeId = await googleapi.runPlaceSearch(searchQuery);\n  console.log(placeId);\n})();;\n```\n\n### Place Details\nGet place details by `place_id`.\n```js\nconst placeId = \"ChIJHegKoJUfyUwRjMxaCcviZDA\"; // placeId of \"Pizza Chicken New York\"\n\n// with promises\ngoogleapi.runPlaceDetails(placeId).then(placeDetails =\u003e {\n  console.log(`place found: ${placeDetails.name}`);\n})\n\n// with async await\n(async () =\u003e {\n  let placeDetails = await googleapi.runPlaceDetails(placeId);\n  console.log(`place found: ${placeDetails.name}`);\n})();\n```\nGet place details by `cid`. This is a deprecated endpoint and not documented in the official google api documentation, but it still works. See also this [answer on stackoverflow](https://stackoverflow.com/a/49374036/6272061)\n```js\nconst cid = \"10056734717913051463\"; // cid of \"Brooklyn Boulders Chicago\"\n\n// with promises\ngoogleapi.runPlaceDetailsCid(cid).then(placeDetails =\u003e {\n  console.log(`place found: ${placeDetails.name} (${placeDetails.cid})`);\n});\n\n// with async await\n(async () =\u003e {\n  let placeDetails = await googleapi.runPlaceDetailsCid(cid);\n  console.log(`place found: ${placeDetails.name} (${placeDetails.cid})`);\n})();\n```\n\n### Place Photos\n⚠️ **Be Aware**: this function returns only the photoUrl, not the image itself.\n```js\nconst photoReference = 'CmRaAAAAqYV1efHXXLX3UB1msekeprgOUD362n4-8lxwYI3aSFANLw51oE1_KeNziEgnnbr5WQzJtQo9SbNnZFRfymg594T9h7yRWnLQL8w1n_ekN6BbyJzg1k0hadSJ4N0i63TmEhA3NIzf_JWUEZcW3VgXJ5FqGhRq7ij6D2Vl8DOSF2yHY1iuTYuAKA';\n\n// with promises\ngoogleapi.runPlacePhotos(photoReference).then(photoUrl =\u003e {\n  console.log(`photo url: ${photoUrl}`);\n});\n\n// with async await\n(async () =\u003e {\n  let photoUrl = await googleapi.runPlacePhotos(photoReference);\n  console.log(`photo url: ${photoUrl}`);\n})();\n```\n\n### Full Example\n1. Search for a place by textquery\n2. get place details from that place\n3. fetch all photo urls from that place\n\n```js\nconst textSearch = \"Nolita Pizza New York\";\n\n// with promises\ngoogleapi.runPlaceSearch(textSearch).then(placeId =\u003e {\n  console.log(`place id found: ${placeId}`);\n  return googleapi.runPlaceDetails(placeId);\n}).then(placeDetails =\u003e {\n  console.log(`place details fetched for ${placeDetails.name} (${placeDetails.place_id})`);\n  const promises = [];\n  placeDetails.photos.map(photo =\u003e {\n    promises.push(googleapi.runPlacePhotos(photo.photo_reference));\n  });\n  return Promise.all(promises);\n}).then(placePhotoUrls =\u003e {\n  console.log(`${placePhotoUrls.length} photo urls fetched:`);\n  console.log(placePhotoUrls);\n});\n\n// with async await\n(async () =\u003e {\n  let placeId = await googleapi.runPlaceSearch(textSearch)\n  console.log(`place id found: ${placeId}`);\n\n  let placeDetails = await googleapi.runPlaceDetails(placeId);\n  console.log(`place details fetched for ${placeDetails.name} (${placeDetails.place_id})`);\n\n  const placePhotoUrls = [];\n  for (const photo of placeDetails.photos) {\n    placePhotoUrls.push(await googleapi.runPlacePhotos(photo.photo_reference));\n  }\n  console.log(`${placePhotoUrls.length} photo urls fetched:`);\n  console.log(placePhotoUrls);\n})();\n```\n## Run Tests (written with AVA js)\n```js\nnpm run test\n```\n\n## ToDo's\n- [ ] run `npm run test` to see missing tests.\n- [ ] escape queries with `encodeURI()` or `encodeURIComponent` -\u003e write tests for them first.\n- [ ] why some request work on google maps webinterface but not with the API, like this one: `Bartleby’s Ice Cream Cakes` -\u003e no results from the API, but finds it on webinterface. I think it could be something with the top appostroph.\n\n# Credits\nWritten by [dcts](www.github.com/dcts) for personal use only. Check my [portfolio website](https://dcts.github.io/CV/). Or go play [tetris](https://dcts-tetris-spheres.firebaseapp.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcts%2Fdcts-google-places-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcts%2Fdcts-google-places-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcts%2Fdcts-google-places-api/lists"}