我知道这听起来很荒谬,但我一直试图从google maps api中读取这些json数据,但似乎没有任何效果
这是代码
app.get('/distance', function(req, res, next) {
request('https://maps.googleapis.com/maps/api/distancematrix/json?origins=Seattle&destinations=San+Francisco&key=' + config.GOOGLE_DISTANCE_API, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
});
});
正文将返回此数据
{
"destination_addresses" : [ "New York, NY, USA" ],
"origin_addresses" : [ "Washington, DC, USA" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "225 mi",
"value" : 361715
},
"duration" : {
"text" : "3 hours 49 mins",
"value" : 13725
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
当我尝试console.log body.destination_addresses
以及body.rows
时,它们都显示未定义。我如何访问它?