2017-05-27 5 views
0

Hier mit Knoten js ill senden Anfrage, aber sie geben mir en Fehler, fügen Sie den Schlüssel zur Konfig. Ich habe einen Schlüssel, weiß aber nicht, wie ich ihn hinzufügen soll?
Mein Code ist:Hinzufügen von Google API-Schlüssel mit Hilfe von Config

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 Fehler; ^

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> 

Also, wie kann ich hinzufügen, Schlüssel, wie sie "mit config" sagen?

Vielen Dank.

Antwort

0

Sie können die Antwort in der Dokumentation:

https://www.npmjs.com/package/googlemaps

es so etwas wie sein sollte:

var publicConfig = { 
    key: '<YOUR-KEY>', 
    stagger_time:  1000, // for elevationPath 
    encode_polylines: false, 
    secure:    true, // use https 
    proxy:    'http://127.0.0.1:9999' // optional, set a proxy for HTTP requests 
}; 
var gmAPI = new GoogleMapsAPI(publicConfig); 

hoffe, das hilft!

Verwandte Themen