node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


Build Status

Google Maps API for Node.js

This library implements the following Google Maps APIs, and can be also used by Google Maps for Work users.

This library is NOT COMPATIBLE with tags < 1.0.0

If you want to migrate from a version older than 1.0.0 check the WIKI for instructions.


npm install googlemaps

What does it cover

Maps API Web Services:


Google Maps Image API


var publicConfig = {
  key: '<YOUR-KEY>',
  stagger_time:       1000, // for elevationPath 
  encode_polylines:   false,
  secure:             true, // use https 
  proxy:              '' // optional, set a proxy for HTTP requests 
var gmAPI = new GoogleMapsAPI(publicConfig);
// or in case you are using Google Maps for Work 
var enterpriseConfig = {
  google_client_id:   '<YOUR-CLIENT-ID>', // to use Google Maps for Work 
  google_private_key: '<YOUR-PRIVATE-KEY>', // to use Google Maps for Work 
  google_channel:     '<YOUR-CHANNEL>' // to use Google Maps for Work application usage tracking 
  stagger_time:       1000, // for elevationPath 
  encode_polylines:   false,
  secure:             true, // use https 
  proxy:              '' // optional, set a proxy for HTTP requests 
var gmAPI = new GoogleMapsAPI(enterpriseConfig);
// geocode API 
var geocodeParams = {
  "address":    "121, Curtain Road, EC2A 3AD, London UK",
  "components": "components=country:GB",
  "bounds":     "55,-1|54,1",
  "language":   "en",
  "region":     "uk"
gmAPI.geocode(geocodeParams, function(err, result){
// reverse geocode API 
var reverseGeocodeParams = {
  "latlng":        "51.1245,-0.0523",
  "result_type":   "postal_code",
  "language":      "en",
  "location_type": "APPROXIMATE"
gmAPI.reverseGeocode(reverseGeocodeParams, function(err, result){

Check out the unit tests for more APIs examples.

Static Maps

var gmAPI = new GoogleMapsAPI();
var params = {
  center: '444 W Main St Lock Haven PA',
  zoom: 15,
  size: '500x400',
  maptype: 'roadmap',
  markers: [
      location: '300 W Main St Lock Haven, PA',
      label   : 'A',
      color   : 'green',
      shadow  : true
      location: '444 W Main St Lock Haven, PA',
      icon: ''
  style: [
      feature: 'road',
      element: 'all',
      rules: {
        hue: '0x00ff00'
  path: [
      color: '0x0000ff',
      weight: '5',
      points: [
gmAPI.staticMap(params); // return static map URL 
gmAPI.staticMap(params, function(err, binaryImage) {
  // fetch asynchronously the binary image 

This example prints the URL for the Static Map image: ""

By giving gm.staticMap an optional callback, you can retreive the static map PNG data:

You will get a map like:

Some Map

For custom markers using the icon parameter, a little-known scale parameter is also available that makes it possible to use high-resolution custom images on devices with retina displays. Set it to 2 and use it together with a @2x http-only image URL (Google's API does not support custom marker images served over https), such as:

  location: '999 Example Road, Earth',
  icon: '',
  scale: 2

Credits to this answer on SO.

Street view

var gmAPI = new GoogleMapsAPI();
var params = {
  location: '51.507868,-0.087689',
  size: '1200x1600',
  heading: 108.4,
  pitch: 7,
  fov: 40
var result = gmAPI.streetView(params);

London - Tower Bridge from London Bridge

Further examples

Please refer to the code, tests and the Google Maps API docs for further usage information.


Criticism/Suggestions/Patches/PullRequests are welcome.

Original contributors list

evnm duncanm sugendran JoshSmith grobot regality spatical

v1.0.0 maintener

moshen fabriziomoscon

Contributions and new issues are welcome!