2015-10-15 27 views
0

我需要访问谷歌道路API以使用从我的node.js服务器捕捉道路特征。但无法这样做..这里是我的代码从node.js服务器访问谷歌道路API v3

var options = {     //setting options..host,port,path etc.. 
     host: 'https://roads.googleapis.com', 
     port: 80, // here i don't know port number. 
     path: '/v1/snapToRoads?path='+snaptoPath+'&interpolate=true&key=*************', 
     method: 'GET', 
     headers: { 
     'Content-Type': 'application/json; charset=utf-8' 
      } 
    }; 

    var request = https.request(options, function(response) { 
    var gpsData = ""; 
     response.on('data', function(chunk) { 
      gpsData += chunk; 
     }); 

     response.on('end', function() { 
      try{ 
       console.log(gpsData); 

      } 
      catch(e) 
      { 
       console.log(e); 

      } 
     }); 

    }); 
    request.on("error",function(e) 
    { 
     console.log(e); 
    }); 
    var dataString = new Buffer(""); 
    request.write(dataString);//writting request to stream 
    request.end(); 

我越来越错误的API调用。 有人可以帮我解决这个问题..?

回答

2

您应该只包含实际的url而不是协议,即http //或https://。 https的端口也是443,但不需要输入。

相关问题