Code Monkey home page Code Monkey logo

gatsby-source-google-places's Introduction

gatsby-source-google-places

Source plugin for pulling data from the Google Places API.

Pre-reqs

Get a Google Places API Key.

Install

npm install --save gatsby-source-google-places
# or
yarn add gatsby-source-google-places

Using

Setup the plugin

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-google-places`,
      options: {
        spaceId: `<your_space_id>`,
        apiKey: '<your_api_key>',
      },
    },
  ],
}

Use query in a page

// pages/places.js
import React from 'react'
import { graphql } from 'gatsby'
import Layout from '../components/layout'

const PlacesPage = ({ data }) => {
  const place = data.googlePlacesPlace
  const reviews = place.childrenGooglePlacesReview.map(r => (
    <div>
      <img height="50" width="50" src={r.profile_photo_url} />
      <strong>{r.author_name} - {r.rating}</strong>
      <p>{`${r.text.substring(0, 250)} ...`}</p>
    </div>
  ))
  return (
    <Layout>
      <h1>{place.name}</h1>
      <p>total ratings: {place.user_ratings_total}</p>
      <p>average: {place.rating}</p>
      <h3>Recent Reviews</h3>
      {reviews}
    </Layout>
  )
}

export const query = graphql`
query {
  googlePlacesPlace {
    name
    rating
    childrenGooglePlacesReview {
      author_name
      text
      rating
      profile_photo_url
    }
    user_ratings_total
  }
}
`

export default PlacesPage

Contribute

Issues, suggestions and PRs welcome!

gatsby-source-google-places's People

Contributors

franklintarter avatar stefanprobst avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.