简体   繁体   中英

Can't seem to find unexpected identifier

For a college project I'm developing an app with Django Framework that allows users to find restaurants and other venues near them, and obtain a route to them through the Google Directions Service.

I just copied the calculateAndDisplayRoute function from the service overview code sample into my template, and I keep getting an unexpected identifier error, but I don't see the problem.

Keep in mind that I'm fairly new to JavaScript, so I might be overlooking something obvious here. Here's the code snippet:

function calculateAndDisplayRoute(directionsService, directionsDisplay) {
    directionsService.route({
      origin: new.google.maps.LatLng(43.0186, -7.5813),
      destination: new.google.maps.LatLng(43.0157, -7.5495),
      travelMode: travel_mode
    }, function(response, status) {
      if (status === 'OK') {
        directionsDisplay.setDirections(response);
      } else {
        window.alert('Directions request failed due to ' + status);
      }
    });
  }

I'm getting the error on the 'origin: ...' line. Origin and destination values are fixed for testing purposes. Here's the complete script: https://pastebin.com/sbNtVLYk

Thanks in advance.

EDIT: full template code: https://pastebin.com/8rhTGPXA

new is a reserved work in JavaScript, see a description here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new

So the invalid lines are

  origin: new.google.maps.LatLng(43.0186, -7.5813),
  destination: new.google.maps.LatLng(43.0157, -7.5495),

This is also being highlighted by the code highlighting here on stackoverflow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM