Sunil
Sunil

Reputation: 929

Accessing google Roads API v3 from node.js server

I need to access google roads api to use snap to roads feature from my node.js server. But unable to do so.. here is my code

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();

I am getting ERRNT error in api call. Can somebody help me about this..?

Upvotes: 0

Views: 389

Answers (1)

Abhijit Deshpande
Abhijit Deshpande

Reputation: 46

You should only include the actual url and not the protocol i.e. http// or https://. Also port for https is 443, but you need not enter that.

Upvotes: 3

Related Questions