Giter Club home page Giter Club logo

vulcan-places's Introduction

Vulcan Places

Install

meteor add vulcan:places

Usage

This package enables two distinct features, which can be used separately or together:

  1. A PlaceControl autocomplete form component that lets users fill in a place via the Google Maps Places API.
  2. A Places collection that can optionally be used to store places as individual documents.

Both require setting your Google Maps API key in your settings.json file's public section:

"googlemaps": {
  "apiKey": "123foo"
}

And install npm packages :

npm install --save @google/maps react-places-autocomplete

Place Form Control

Uses https://github.com/kenny-hibino/react-places-autocomplete.

To use:

  1. Import PlaceControl from 'meteor/vulcan:places'
  2. Create a placeName custom field on one of your collections
  3. Set this field's control property to PlaceControl.
  4. Also create a placeId field on the same collection.
  5. Add placeName and placeId to the appropriate fragments.

Places Collection

Uses https://github.com/googlemaps/google-maps-services-js.

The Places collection makes it easy to check for a placeId field on a newly inserted or edited document, and if present insert a new place document.

There are two distinct ways to use this collection:

  1. Associate a place with one or more documents from another collection, such as adding a location to individual photos.
  2. Build a Yelp-like directory of places by using the Places collection as a base and adding your own custom fields to it.

checkAndAddPlace

The package exports a checkAndAddPlace function that takes a placeId, checks the Places collection for any existing document with that id, and if none is found queries the Google Places API for the place details before inserting it in the database:

import { addCallback } from 'meteor/vulcan:core';
import { checkAndAddPlace } from 'meteor/vulcan:places';

function postsNewCheckForNewPlace (document, user) {
  if (document.placeId) checkAndAddPlace(document.placeId);
}
addCallback('posts.new.async', postsNewCheckForNewPlace);

function postsEditCheckForNewPlace (document) {
  if (document.placeId) checkAndAddPlace(document.placeId);
}
addCallback('posts.edit.async', postsEditCheckForNewPlace);

Resolvers

The package also creates resolvers for the Places collection.

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.