• Stars
    star
    196
  • Rank 198,553 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ—Ί Meteor package for the Google Maps Javascript API v3

Meteor Google Maps

Join the chat at https://gitter.im/dburles/meteor-google-maps

Latest version of the Google Maps Javascript API with an interface designed for Meteor.

  • Supports multiple map instances
  • Ability to only load the API when it's required
  • Provides callbacks for individual maps when they render
  • API key + libraries
  • StreetViewPanorama support

Table of Contents

Note

The maps API is client-side only. Server side support may be added soon.

Installation

$ meteor add dburles:google-maps

Alternatively if you wish to add the package from within another package and have GoogleMaps available outside of package scope, use api.imply in your package.js.

Examples

Reactive geolocation

How to create a reactive Google map

React example

Demo project for the examples below

Usage Overview

Call the load method to load the maps API.

if (Meteor.isClient) {
  Meteor.startup(function() {
    GoogleMaps.load();
  });
}

If you prefer to load the maps API only once it's required, you may do so from within a Template onRendered hook.

Template.contact.onRendered(function() {
  GoogleMaps.load();
});

Wrap the map template to set the width and height.

<body>
  <div class="map-container">
    {{> googleMap name="exampleMap" options=exampleMapOptions}}
  </div>
</body>
.map-container {
  width: 800px;
  max-width: 100%;
  height: 500px;
}

Pass through the map initialization options by creating a template helper. This will only run once.

Template.body.helpers({
  exampleMapOptions: function() {
    // Make sure the maps API has loaded
    if (GoogleMaps.loaded()) {
      // Map initialization options
      return {
        center: new google.maps.LatLng(-37.8136, 144.9631),
        zoom: 8
      };
    }
  }
});

Place the ready callback within the template onCreated callback. This is also where you handle map events and reactive updates.

Template.body.onCreated(function() {
  // We can use the `ready` callback to interact with the map API once the map is ready.
  GoogleMaps.ready('exampleMap', function(map) {
    // Add a marker to the map once it's ready
    var marker = new google.maps.Marker({
      position: map.options.center,
      map: map.instance
    });
  });
});

Access a map instance any time by using the maps object.

GoogleMaps.maps.exampleMap.instance

API

Blaze Template

{{> googleMap [type=String] name=String options=Object}}

  • type (Optional)
    • Currently supported types: Map, StreetViewPanorama (defaults to 'Map')
  • name
    • Provide a name to reference this map
  • options
    • Map initialization options

create

GoogleMaps.create({object})

An alternative to using the googleMap Blaze template. Call this function to create a new map instance and attach it to a DOM element.

Options:

  • name - Name to reference this map.
  • element - A DOM element to attach the map to.
  • options - The map options.
  • type (optional) - Map or StreetViewPanorama. Defaults to Map.

Example:

GoogleMaps.create({
  name: 'exampleMap',
  element: document.getElementById('exampleMap'),
  options: {
    center: new google.maps.LatLng(-37.8136, 144.9631),
    zoom: 8
  }
});

load

GoogleMaps.load([options])

Loads the map API. Options passed in are automatically appended to the maps url. By default v3.exp will be loaded. For full documentation on these options see https://developers.google.com/maps/documentation/javascript/tutorial#Loading_the_Maps_API

Example:

GoogleMaps.load({ v: '3', key: '12345', libraries: 'geometry,places' });

loadUtilityLibrary

GoogleMaps.loadUtilityLibrary('/path/to/library.js')

A method to ease loading external utility libraries. These libraries will load once the Google Maps API has initialized.

loaded

GoogleMaps.loaded()

Reactive method which returns true once the maps API has loaded, or after manually calling GoogleMaps.initialize() (See further down).

ready

GoogleMaps.ready('name', callback)

Runs once the specified map has rendered.

  • name String
  • callback Function

Example:

GoogleMaps.ready('exampleMap', function(map) {
  // map.instance, map.options
});

The callback function returns an object containing two properties:

  • instance
    • The Google map instance
  • options
    • The options passed through from the Template helper (see Usage Overview above)

You can also access this object directly by name:

GoogleMaps.maps.exampleMap

initialize

GoogleMaps.initialize()

This function is passed into the Google maps URL as the callback parameter when calling GoogleMaps.load(). In the case where the maps library has already been loaded by some other means, calling GoogleMaps.initialize() will set GoogleMaps.loaded() to true.

Mobile platforms

If you're targeting mobile platforms you'll need to configure the following access rules in mobile-config.js.

App.accessRule('*.google.com/*');
App.accessRule('*.googleapis.com/*');
App.accessRule('*.gstatic.com/*');

For more refer to the official documentation.

License

MIT

More Repositories

1

meteor-collection-helpers

βš™οΈ Meteor package that allows you to define helpers on your collections
JavaScript
497
star
2

meteor-presence

πŸ‘₯ Meteor package to help track users' presence
JavaScript
87
star
3

meteor-two-factor

πŸ” Two factor authentication package for accounts-password
JavaScript
81
star
4

meteor-spacebars-tohtml

Meteor package to ease rendering spacebars to html
JavaScript
36
star
5

mystical

🌌 A CSS-in-JS library for constraint based design
JavaScript
32
star
6

reactive-maps-example

Example Meteor application demonstrating a reactive Google map
JavaScript
29
star
7

meteor-google-maps-react-example

An example of using the Meteor package dburles:meteor-google-maps with React
JavaScript
20
star
8

meteor-guide-starter-react

A basic starter application based on the Meteor guide
JavaScript
20
star
9

geolocation-example

JavaScript
20
star
10

flow-router-react-example

Flow Router and React example
JavaScript
19
star
11

meteor-capture-pubsub2

A Meteor project demonstrating publishing data from an external API
JavaScript
16
star
12

load-more-list

Meteor application demonstrating a paginated list component
JavaScript
15
star
13

meteor-flow-router-map

Meteor package for Flow Router
JavaScript
15
star
14

meteor-google-maps-demo

Demo project for meteor-google-maps package
JavaScript
13
star
15

meteor-capture-incoming

A Meteor project demonstrating a Twitter style incoming posts dialog
JavaScript
12
star
16

flow-router-blaze-example

Flow Router and Blaze example
JavaScript
11
star
17

two-factor-example

JavaScript
9
star
18

treel

A Meteor application
JavaScript
9
star
19

react-tiny-state

Tiny React global state containers
JavaScript
8
star
20

meteor-eslint

Meteor eslint package
JavaScript
7
star
21

meteor-capture-modal-example

A Meteor project demonstrating a basic modal pattern
JavaScript
6
star
22

ssu16

SSU16: Sound Sequencing Unit
JavaScript
6
star
23

recompose-forms

JavaScript
6
star
24

reactive-relations

Intelligent reactive relational publications for Meteor
JavaScript
6
star
25

meteor-packery

Meteor package for Packery layout library
JavaScript
5
star
26

graphql-client

A simple GraphQL client with cache
JavaScript
4
star
27

bookstore

JavaScript
4
star
28

cellar

A wine cellar app made with Meteor
JavaScript
3
star
29

meteor-react-base

β˜„οΈMeteor and βš›οΈ React example/base starter app
JavaScript
3
star
30

meteor-session-unset

JavaScript
3
star
31

meteor-capture-pubsub

A Meteor project demonstrating publishing data that doesn't come from Mongo
JavaScript
3
star
32

parcel-react-base

πŸ“¦ Parcel and βš›οΈ React example/base starter app
JavaScript
3
star
33

vcvm

VCV Rack modules explorer
JavaScript
2
star
34

diy-graphql-server

A simple but fully functional GraphQL server in pure ESM
JavaScript
2
star
35

awesome-chat

A live chat app build demonstrated at Melb Meteor 9
JavaScript
2
star
36

meteor-lazy

Meteor package for lazy developers
JavaScript
2
star
37

meteor-dogescript

JavaScript
2
star
38

route2

πŸ”— A simple client side router with React support
JavaScript
2
star
39

simple-meteor-react-demo

JavaScript
2
star
40

conduit-example

JavaScript
2
star
41

webpack4-react-base

JavaScript
2
star
42

react-shared-usestate

Create global React useState hooks
JavaScript
2
star
43

meteor-conduit

JavaScript
1
star
44

snowpack-react-base

JavaScript
1
star
45

spacex

JavaScript
1
star
46

meteor-school

JavaScript
1
star
47

storybook-dynamic-import-issue

JavaScript
1
star
48

base-app

JavaScript
1
star
49

meteor-presence-live-caret

JavaScript
1
star
50

meteor-lint-config-example

JavaScript
1
star
51

chrome-tab-popup

A chrome extension that provides a clean and simple popup list to switch open tabs
JavaScript
1
star
52

route2-example

Example app for https://github.com/dburles/route2
JavaScript
1
star
53

state-forms

JavaScript
1
star
54

whiski

JavaScript
1
star
55

query-array-demo

Demo application for Meteor Iron Router Query Array package
JavaScript
1
star
56

meteor-stringify-pretty

JavaScript
1
star
57

deno-ssr-url-modules-experiment

JavaScript
1
star
58

scoped-style-components

Lightweight React components for scoping styles natively. CSS-in-JS without the runtime!
TypeScript
1
star