Skip to content
This repository was archived by the owner on Aug 10, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
774ec97
Fix multiple path serialization in static maps
moshen Aug 8, 2026
9f5da5e
Add type param to place search and stop forcing default radius
moshen Aug 8, 2026
33683f1
Request static map binary data as a Buffer
moshen Aug 8, 2026
c9560a6
Raise static map max URL length to 8192
moshen Aug 8, 2026
949c344
Fix min/max price swap typo in placeSearchNearby
moshen Aug 8, 2026
8a2cc88
Fix geocode components example in README
moshen Aug 8, 2026
55b5647
Update qs to ^6.3.2 to fix prototype pollution
moshen Aug 8, 2026
9a9cbfe
Support pre-encoded polylines (enc) in static map paths
moshen Aug 8, 2026
294480b
Support 'now' as a value for departure_time/arrival_time
moshen Aug 8, 2026
7472f93
Remove committed API key; integration tests read it from the env
moshen Aug 8, 2026
7dfe0d4
Make static-map/street-view URL assertions never log the API key
moshen Aug 8, 2026
ca8e755
Make integration tests robust to Google response drift
moshen Aug 9, 2026
7a95e8e
Add decodePolyline utility for decoding encoded polylines
moshen Aug 9, 2026
8902c42
Add transit_mode and transit_routing_preference params
moshen Aug 9, 2026
40876e5
Support Google's newer style format in static maps
moshen Aug 9, 2026
6e95767
Surface X-StaticMap-API-Warning header in staticMap callback
moshen Aug 9, 2026
d62c0c2
Document that empty array waypoints no longer produce broken URLs
moshen Aug 9, 2026
3813294
Replace retired Google Chart API icon in staticmaps PNG test
moshen Aug 9, 2026
82bc6dd
Allow overriding the Google Maps API base URL via config
moshen Aug 9, 2026
4c3de97
Replace qs with node querystring builtin
moshen Aug 9, 2026
346dfb7
Replace Travis CI with GitHub Actions
moshen Aug 9, 2026
3db41da
Fix jsonParser test to be V8 error message agnostic
moshen Aug 9, 2026
2b772ac
Make breaking changes opt-in via config flags
moshen Aug 9, 2026
1b47d0d
Deprecate package in favor of @googlemaps/google-maps-services-js
moshen Aug 9, 2026
edddcc6
Bump version to 1.13.0
moshen Aug 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "CI"
on: [push]

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Setup Node
uses: actions/setup-node@v5
with:
node-version: 24

- name: Install dependencies
run: npm ci

- name: Test
run: npm test

matrix-tests:
name: Test Node versions
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
node_version: [18, 20, 22, 24]
steps:
- uses: actions/checkout@v5

- name: Setup Node
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node_version }}

- name: Install dependencies
run: npm install

- name: Test
run: npm test

integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v5

- name: Setup Node
uses: actions/setup-node@v5
with:
node-version: 24

- name: Install dependencies
run: npm ci

- name: Integration Test
run: npm run integration-test
env:
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
npm-debug.log
npm-debug.log
test/simpleConfig.json
.env
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[![Build Status](https://travis-ci.org/moshen/node-googlemaps.svg?branch=master)](https://travis-ci.org/moshen/node-googlemaps)
[![CI](https://github.com/moshen/node-googlemaps/actions/workflows/ci.yml/badge.svg)](https://github.com/moshen/node-googlemaps/actions/workflows/ci.yml)

# Google Maps API for Node.js

> **DEPRECATED:** This package is no longer maintained. Please use Google's official Node.js client library [`@googlemaps/google-maps-services-js`](https://github.com/googlemaps/google-maps-services-js) instead.

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

* [Maps API Web Services](https://developers.google.com/maps/documentation/webservices/)
Expand Down Expand Up @@ -67,7 +69,7 @@ var gmAPI = new GoogleMapsAPI(enterpriseConfig);
// geocode API
var geocodeParams = {
"address": "121, Curtain Road, EC2A 3AD, London UK",
"components": "components=country:GB",
"components": "country:GB",
"bounds": "55,-1|54,1",
"language": "en",
"region": "uk"
Expand All @@ -92,6 +94,34 @@ gmAPI.reverseGeocode(reverseGeocodeParams, function(err, result){

Check out the [unit tests](./tree/new-major-version/test/unit/) for more APIs examples.

### Optional configuration

The following config keys control behavior that was added as bug fixes but
could break existing callers. Each defaults to the old (pre-fix) behavior
so existing code keeps working unless you opt in.

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `static_map_binary` | boolean | `false` | When `true`, `staticMap` returns image data as a `Buffer` instead of a string. Use this if you save the image to a file (the old string output produced unusable files). |
| `static_map_warnings` | boolean | `false` | When `true`, Google's `X-StaticMap-API-Warning` response header is surfaced as a non-fatal error (`err.isWarning = true`) in the `staticMap` callback, alongside the image data. By default warnings are silently ignored. |
| `places_default_radius` | boolean | `true` | When `true`, `placeSearch` defaults `radius` to 50000 meters (the max) if omitted and `rankby=prominence`. Set to `false` to omit the radius entirely (Google ranks differently without it). |
| `google_api_url` | string | `http://maps.googleapis.com` | Override the base API URL forHTTP requests. Useful for mocking in tests. |
| `google_secure_api_url` | string | `https://maps.googleapis.com` | Override the base API URL for HTTPS requests. |

### Mocking responses

To mock the Google API endpoints for local development or CI, override the
base URLs in your config:

```javascript
var config = {
key: '<YOUR-KEY>',
google_api_url: 'http://localhost:3000/fixture',
google_secure_api_url: 'https://localhost:3443/fixture'
};
var gmAPI = new GoogleMapsAPI(config);
```

### Static Maps

```javascript
Expand Down Expand Up @@ -180,6 +210,27 @@ var result = gmAPI.streetView(params);
Please refer to the code, [tests](http://github.com/moshen/node-googlemaps/tree/master/test/) and the [Google Maps API docs](https://developers.google.com/maps/web-services/) for further usage information.


### Tests

The unit tests run offline with no credentials:

```
npm test
```

The integration tests make real requests to the Google Maps API and require a
valid, billing-enabled API key. Provide it via the `GOOGLE_MAPS_API_KEY`
environment variable (no key is committed to this repository):

```
GOOGLE_MAPS_API_KEY=your-key-here npm run integration-test
```

`GOOGLE_MAPS_SECURE` may be set to `false` to use http (defaults to `true` /
https). For local development you may instead create a git-ignored
`test/simpleConfig.json` of the form `{"key": "...", "secure": true}`.


### Contributions
Criticism/Suggestions/Patches/PullRequests are welcome.

Expand Down
26 changes: 18 additions & 8 deletions lib/config/constants.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"ACCEPTED_CONFIG_KEYS": {
"encode_polylines": "boolean",
"google_client_id": "string",
"google_channel": "string",
"key": "string",
"proxy": "string",
"secure": "boolean",
"stagger_time": "number"
"encode_polylines": "boolean",
"google_client_id": "string",
"google_channel": "string",
"google_api_url": "string",
"google_secure_api_url": "string",
"key": "string",
"proxy": "string",
"secure": "boolean",
"stagger_time": "number",
"static_map_binary": "boolean",
"static_map_warnings": "boolean",
"places_default_radius": "boolean"
},

"ACCEPTED_PARAMS": {
Expand All @@ -22,6 +27,7 @@
"radius": "number",
"rankby": "string",
"sensor": "string",
"type": "string",
"types": "string"
},
"place-search-text": {
Expand Down Expand Up @@ -73,6 +79,8 @@
"language": "string",
"avoid": "string",
"units": "string",
"transit_mode": "string",
"transit_routing_preference": "string",
"departure_time": "date",
"arrival_time": "date",
"traffic_model": "string"
Expand All @@ -87,6 +95,8 @@
"language": "string",
"region": "string",
"units": "string",
"transit_mode": "string",
"transit_routing_preference": "string",
"departure_time": "date",
"arrival_time": "date",
"traffic_model": "string"
Expand Down Expand Up @@ -136,7 +146,7 @@
"place-search-text": 2048,
"place-autocomplete": 2048,
"reverse-geocode": 2048,
"static-map": 2048,
"static-map": 8192,
"timezone": 2048,
"street-view": 2048
},
Expand Down
19 changes: 12 additions & 7 deletions lib/config/getDefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
module.exports = function() {

return {
encode_polylines: true,
google_client_id: null,
google_channel: null,
key: null,
proxy: null,
secure: false,
stagger_time: 200,
encode_polylines: true,
google_client_id: null,
google_channel: null,
google_api_url: 'http://maps.googleapis.com',
google_secure_api_url: 'https://maps.googleapis.com',
key: null,
proxy: null,
secure: false,
stagger_time: 200,
static_map_binary: false,
static_map_warnings: false,
places_default_radius: true,
set google_private_key(value) {
if (typeof value !== 'undefined' && value !== null) {
// Google private keys are URL friendly base64, needs to be replaced with base64 valid characters
Expand Down
13 changes: 13 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var _makeRequest = require('./utils/makeRequest');
var _assignParams = require('./utils/assignParams');
var _jsonParser = require('./utils/jsonParser');
var _encodePolyline = require('./utils/encodePolylines');
var _decodePolyline = require('./utils/decodePolylines');
var _getDefaultConfig = require('./config/getDefault');
var _constants = require('./config/constants');

Expand Down Expand Up @@ -243,6 +244,18 @@ GoogleMapsAPI.prototype.checkAndConvertPoint = function(input) {
};


/**
* Decodes an encoded polyline string (e.g. from the Directions API
* overview_polyline.points field) into an array of [lat, lng] pairs.
*
* Google documentation reference: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
*
* var coords = gmAPI.decodePolyline(encoded);
* // coords = [[38.5, -120.2], [40.7, -120.95], ...]
*/
GoogleMapsAPI.prototype.decodePolyline = _decodePolyline;


module.exports = GoogleMapsAPI;

// TODO improve this and move to a separate file
Expand Down
4 changes: 2 additions & 2 deletions lib/placeSearchNearby.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = function(params, callback) {
return callback(new Error('If rankby=distance is specified, then one or more of keyword, name, or types is required.'));
}
delete args.radius;
} else if (args.rankby === PLACES_RANKBY_DEFAULT) {
} else if (args.rankby === PLACES_RANKBY_DEFAULT && this.config.places_default_radius) {
if (args.radius == null) {
args.radius = MAX_RADIUS;
}
Expand All @@ -80,7 +80,7 @@ module.exports = function(params, callback) {
}
if (args.minprice > args.maxprice) {
var swap = args.maxprice;
args.maxprice = ags.minprice;
args.maxprice = args.minprice;
args.minprice = swap;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/assignParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var check = require('check-types');

if (expectedType == 'date') {

if (check.date(newParams[ key ])) {
if (newParams[ key ] === 'now' || check.date(newParams[ key ])) {
params[ key ] = newParams[ key ];
}

Expand Down
51 changes: 51 additions & 0 deletions lib/utils/decodePolylines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Decodes an encoded polyline string into an array of [lat, lng] pairs.
*
* Algorithm from Google's polyline encoding documentation:
* https://developers.google.com/maps/documentation/utilities/polylinealgorithm
*
* input = '_p~iF~ps|U_ulLnnqC_mqNvxq`@'
* output = [[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]]
*/
module.exports = function(encoded) {

if (typeof encoded !== 'string') {
throw new Error('Encoded polyline must be a string');
}

var index = 0;
var lat = 0;
var lng = 0;
var coordinates = [];

while (index < encoded.length) {

var result = 1;
var shift = 0;
var b;

do {
b = encoded.charCodeAt(index++) - 63 - 1;
result += b << shift;
shift += 5;
} while (b >= 0x1f);

lat += (result & 1) ? ~(result >> 1) : (result >> 1);

result = 1;
shift = 0;

do {
b = encoded.charCodeAt(index++) - 63 - 1;
result += b << shift;
shift += 5;
} while (b >= 0x1f);

lng += (result & 1) ? ~(result >> 1) : (result >> 1);

coordinates.push([lat / 1e5, lng / 1e5]);
}

return coordinates;

};
Loading