├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 'stable' 5 | - '7' 6 | - '6' 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Mikko Haapoja 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # google-maps-image-api 2 | 3 | **Allows you to easily get Google Maps Image API urls.** 4 | 5 | Google Maps Image API allows you to get static images of a 2d map or streetview. This module will return the url of such an image. The options correlate to those in the API. 6 | 7 | ## usage 8 | 9 | ```js 10 | const image = require('google-maps-image-api') 11 | image({ 12 | type: 'staticmap', 13 | center: '40.714728,-73.998672' 14 | }) // -> url 15 | ``` 16 | 17 | ## static maps 18 | 19 | ### required parameters 20 | 21 | ```javascript 22 | { 23 | type: 'staticmap', 24 | center: '40.714728,-73.998672' // can also be a street address 25 | } 26 | ``` 27 | 28 | ### optional parameters 29 | 30 | ```javascript 31 | { 32 | key: '', // your Google API Key 33 | zoom: 14, // 0 = entire world, 21 = streets 34 | size: '320x240', // size of the image 35 | scale: 1, // for retina screens this should be 2 36 | format: 'JPEG', // or 'PNG' or 'GIF' 37 | maptype: 'roadmap', // or 'satellite' or 'hybrid' or 'terrain' 38 | language: 'en', // language of the map 39 | 40 | region: 'us', // country code in ccTLD 41 | // defines the appropriate borders to display, based on geo-political sensitivities 42 | 43 | markers: 'color:blue|label:S|11211|11206|11222', // add markers to the map 44 | // see https://developers.google.com/maps/documentation/staticmaps/index#Markers 45 | 46 | path: 'color:0x0000ff|weight:5|40.737102,-73.990318|40.749825,-73.987963', 47 | // Add a path to the map. A path can be filled or just a line. 48 | // see https://developers.google.com/maps/documentation/staticmaps/index#Paths 49 | 50 | visible: 'Toronto', // a location that should be visible 51 | // This can be either long,lat or a location name. 52 | 53 | style: 'feature:administrative|element:labels|weight:3.9|visibility:on|inverse_lightness:true', 54 | // how features are rendered eg. roads, parks, etc. 55 | // see https://developers.google.com/maps/documentation/staticmaps/index#StyledMaps 56 | } 57 | ``` 58 | 59 | ## streetview pictures 60 | 61 | ### required parameters 62 | 63 | ```javascript 64 | { 65 | type: 'streetview', 66 | // You must define either location or pano. 67 | location: 'Toronto', // location name or long,lat 68 | pano: '', // id of a specific panorama 69 | } 70 | ``` 71 | 72 | ### optional parameters 73 | 74 | ```javascript 75 | { 76 | key: '', // your Google API key 77 | size: '320x240', // size of the image 78 | heading: 45, // bearing (direction) of the camera. 0 - 360. 0 == North 79 | fov: 90, // field of view in degrees. 80 | pitch: 0, // up/down angle of the camera. 90 = straight up. -90 = straight down 81 | } 82 | ``` 83 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** @module google-maps-image-api */ 2 | 'use strict' 3 | 4 | var querystring = require( 'querystring' ); 5 | 6 | var BASE_URL = 'https://maps.googleapis.com/maps/api/'; 7 | 8 | module.exports = function( opts ) { 9 | 10 | var zoom = typeof opts.zoom === 'number' ? opts.zoom : 14; 11 | var size = opts.size || '320x240'; 12 | 13 | if( opts.type == 'staticmap' ) { 14 | 15 | if( opts.center === undefined ) { 16 | 17 | throw new Error( 'center must be defined in options' ); 18 | } else if( opts.type === undefined ) { 19 | 20 | throw new Error( 'type must be defined in options' ); 21 | } 22 | } else if( opts.type == 'streetview' ) { 23 | 24 | if( opts.location === undefined && opts.pano === undefined ) { 25 | 26 | throw new Error( 'you must pass in location in options' ); 27 | } 28 | } else { 29 | 30 | throw new Error( opts.type + ' is an invalid type. Use "staticmap" or "streetview".' ); 31 | } 32 | 33 | return BASE_URL + opts.type + '?' + querystring.stringify( opts ); 34 | }; 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "google-maps-image-api-url", 3 | "version": "1.0.3", 4 | "description": "This is an easy way to consume the Google Maps Image API to render static maps or street views", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "node test/index.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/Jam3/google-maps-image-api-url.git" 15 | }, 16 | "keywords": [ 17 | "google", 18 | "maps", 19 | "image", 20 | "api" 21 | ], 22 | "author": "Mikko Haapoja ", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/Jam3/google-maps-image-api-url/issues" 26 | }, 27 | "homepage": "https://github.com/Jam3/google-maps-image-api-url" 28 | } 29 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const assert = require( 'assert' ); 4 | const imageAPI = require( '..' ); 5 | 6 | assert.strictEqual( imageAPI( { 7 | 8 | type: 'staticmap', 9 | center: '43.653226,-79.3831843', 10 | style: 'feature:landscape|hue:0xFF00FF|saturation:100|lightness:-50' 11 | }), `\ 12 | https://maps.googleapis.com/maps/api/staticmap?type=staticmap\ 13 | ¢er=43.653226%2C-79.3831843&style=feature%3Alandscape\ 14 | %7Chue%3A0xFF00FF%7Csaturation%3A100%7Clightness%3A-50` ); 15 | 16 | assert.strictEqual( imageAPI( { 17 | 18 | type: 'streetview', 19 | location: 'Bay Street, Toronto' 20 | }), `\ 21 | https://maps.googleapis.com/maps/api/streetview?type=streetview\ 22 | &location=Bay%20Street%2C%20Toronto` ); 23 | --------------------------------------------------------------------------------