google-maps-large-size-image
v0.0.2
Published
Create large size high resolution image from google maps.
Downloads
119
Maintainers
Readme
google-maps-large-size-image
Fetch high resolution large size maps image from Google Maps by passing maps extent and zoom level.
Features
:hammer: Installation
Use npm or compatible tool.
npm install google-maps-large-size-image
:popcorn: Usage
This library is based on Google Maps Static API. The API key for the same is required.
const fs = require('fs').promises;
const path = require('path');
const {LargeMap} = require('google-maps-large-size-image');
require('dotenv').config();
// initiate the LargeMap instance
const lm = new LargeMap(process.env.GOOGLE_MAPS_API_KEY, {
scale: 2,
mapType: 'terrain',
region: 'in',
style: 'feature:road|color:yellow'
});
(async () => {
const extent = [72.61, 18.76, 75.28, 21.62];
const zoom = 10;
try {
const img = await lm.getImage(extent, zoom);
await fs.writeFile(path.join(process.cwd(), '/output.jpg'), img);
} catch (err) {
console.error(err);
}
console.log('done!');
})();
:blue_car: API
new LargMap(googleMapsAPIKye, options?)
Return an instance to fetch map images by passing API key.
options
JSON object that can have google static map parameters. scale
parameter is the key to get high resolution image, please read more in API documentation.
Method
getImage(extent, zoom?)
extent
an array of coordinates:[ bottom left long, bottom left lat, top right long, top right lat ]
zoom
integer, zoom level of Google Maps. Default value is 8.