Saturday, 27 May 2017

How can i add google API key?

Here using node js ill send request but they give me en error ,add key to the config. I have a key but dont know how to add it?
My code is:

var GoogleMapsAPI = require('googlemaps');
var config = require('config');
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: 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe%7C996600'
        }
    ],
    style: [
        {
            feature: 'road',
            element: 'all',
            rules: {
                hue: '0x00ff00'
            }
        }
    ],
    path: [
        {
            color: '0x0000ff',
            weight: '5',
            points: [
                '41.139817,-77.454439',
                '41.138621,-77.451596'
            ]
        }
    ]
};
gmAPI.staticMap(params); // return static map URL
gmAPI.staticMap(params, function(err, binaryImage) {
    // fetch asynchronously the binary image
});



and they give me an error:

WARNING: No configurations found in configuration directory:/home/okayg/webstorm_projects/Google_map_API/config
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.

/home/okayg/webstorm_projects/Google_map_API/node_modules/googlemaps/lib/staticMap.js:28 throw error; ^

Error: The staticMap API requires a key. You can add it to the config.
    at module.exports [as staticMap] (/home/okayg/webstorm_projects/Google_map_API/node_modules/googlemaps/lib/staticMap.js:40:36)
    at Object.<anonymous> (/home/okayg/webstorm_projects/Google_map_API/static_map.js:47:7)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:990:3



So, how can i add key as they say "using config"?

Thank you.



via vaishali bagul

No comments:

Post a Comment