Last active
January 26, 2018 21:43
-
-
Save marlonlom/9bb1da21e86247909024d91ef0b65f8f to your computer and use it in GitHub Desktop.
Google staticmaps Router implementation. Used for map images downloading using Nodejs + ExpressJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Google staticmaps Router implementation. | |
*/ | |
const express = require('express'), | |
request = require('request'), | |
router = express.Router(), | |
StaticMaps = { | |
baseHost: "https://maps.googleapis.com/maps/api" | |
}; | |
/** | |
* Download google staticmaps image. | |
*/ | |
router.get('/staticmap', (req, resp) => { | |
let map_position = req.query.center, | |
marker_label = req.query.marker_label, | |
image_url = StaticMaps.baseHost | |
.concat('/staticmap?center=#MAP_LOCATION&zoom=16&scale=1&size=260x200&maptype=roadmap&format=jpg&visual_refresh=true&markers=size:small%7Ccolor:0xff0000%7Clabel:#MARKER_LABEL') | |
.replace('#MARKER_LABEL', encodeURIComponent(marker_label)) | |
.replace('#MAP_LOCATION', map_position); | |
request(image_url).pipe(resp); | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Available request url parameters:
Usage:
Adds as a router to ExpressJS Server implementation.
Then, in a web browser:
<server_url>/staticmap?center=#center&marker_label=#marker_label
Feel free to use and extend.