百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

meteor-google-maps

> 包管理
开源

Google Maps JavaScript API v3 的流星包

195 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Google Maps JavaScript API v3 的流星包

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

  • Installation
  • Examples
  • Usage Overview
  • API
    • Blaze Template
    • create
    • load
    • loadUtilityLibrary
    • loaded
    • ready
    • initialize
  • Mobile Platforms
  • License

Note

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

Installation

bash
$ 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.

javascript
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.

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

Wrap the map template to set the width and height.

xml

  
css
.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.

javascript
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.

javascript
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.

javascript
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:

javascript
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:

javascript
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:

javascript
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:

javascript
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.

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

For more refer to the official documentation.

License

MIT

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptgoogle-mapsgoogle-maps-apimeteormeteor-package

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image