Объедините API направления Google Maps от Node.JS с веб-сайтом HTML - PullRequest
0 голосов
/ 09 октября 2018

Я запускаю Node.JS с Google Maps Directions API для генерации маршрута:

googleMapsClient.directions({
  origin: origin,
  destination: destination,
  waypoints: waypoints,
  mode: 'walking',
  units: 'imperial'
})
.asPromise()
.then(response => {
  return res.json(response);
})
.catch(error => {
  return res.status(500).json({ error: 'bummer' });
});

Это генерирует вывод, подобный следующему:

{ status: 200,
  headers:
   { 'content-type': 'application/json; charset=UTF-8',
     date: 'Tue, 09 Oct 2018 10:59:40 GMT',
     expires: 'Wed, 10 Oct 2018 10:59:40 GMT',
     'cache-control': 'public, max-age=86400',
     server: 'mafe',
     'x-xss-protection': '1; mode=block',
     'x-frame-options': 'SAMEORIGIN',
     'alt-svc': 'quic=":443"; ma=2592000; v="44,43,39,35"',
     'accept-ranges': 'none',
     vary: 'Accept-Language,Accept-Encoding',
     connection: 'close' },
  json:
   { geocoded_waypoints: [ [Object], [Object], [Object], [Object] ],
     routes: [ [Object] ],
     status: 'OK' },
  requestUrl: 'https://maps.googleapis.com/maps/api/directions/json?destination=40.73061%2C-73.935242&mode=walking&origin=40.73061%2C-73.935242&units=metric&waypoints=40.73299509474847%2C-73.94852594455978%7C40.73972377110435%2C-73.92878253439615&key=MYKEY',
  query:
   { destination: '40.73061,-73.935242',
     mode: 'walking',
     origin: '40.73061,-73.935242',
     units: 'metric',
     waypoints: '40.73299509474847,-73.94852594455978|40.73972377110435,-73.92878253439615',
     key: 'MYKEY' } }

Это я быхотел бы показать на HTML веб-сайте что-то вроде:

var map = new google.maps.Map(document.getElementById('map'));
directionsDisplay.setMap(map);
directionsDisplay.setDirections(response);

Но это не получается с:

InvalidValueError: setDirections: in property routes: not an Array

localhost: 109

Как я могу показать мой выводна Google Maps в HTML?

...