im试图在follow函数之外获取两个值 lat 和 lng ,但是没有结果,有什么建议吗?我想拥有两个值 latOk 和 lngOk 供将来使用。
var https = require('https');
var lat;
var lng;
function getCall(callback) {
//initialize options values, the value of the method can be changed to POST to make https post calls
var options = {
protocol: 'https:',
host: 'maps.googleapis.com',
path: '/my_path',
method: 'GET'
};
//making the https get call
https.request(options, function(res) {
let data = ''
// A chunk of data has been recieved from request stream.
res.on('data', function(chunk) {
data += chunk;
});
// Once the whole response has been received, return response as callback
res.on('end', () => {
var resultsjs = JSON.parse(data);
lat = resultsjs.location.lat;
lng = resultsjs.location.lng;
});
})
.on('error', function(err) {
callback(err);
});
}
var latOk = lat;
var lngOk = lng;