Distance Matrix Service with Google Maps API Returning Uncaught Type Error

Basically, I am just doing this tutorial https://codelabs.developers.google.com/codelabs/google-maps-simple-store-locator/

However, when I tried to switch out the tutorial coordinates for my own coordinates for locations where you can get COVID tests, I can’t get the info window to work. I get the uncaught type error below.

This line from the function below seems to be where the problem is.

  const distanceText = element.distance.text;

I also tried plugging my coordinates into this URL to confirm my coordinates were valid.


 const service = new google.maps.DistanceMatrixService();
  const getDistanceMatrix =
    (service, parameters) => new Promise((resolve, reject) => {
      service.getDistanceMatrix(parameters, (response, status) => {
        if (status != google.maps.DistanceMatrixStatus.OK) {
        } else {
          const distances = [];
          const results = response.rows[0].elements;
          for (let j = 0; j < results.length; j++) {
            const element = results[j];
            const distanceText = element.distance.text;
            const distanceVal = element.distance.value;
            const distanceObject = {
              storeid: stores[j],
              distanceText: distanceText,
              distanceVal: distanceVal,


Uncaught TypeError: Cannot read property 'text' of undefined
        at app.js:225
        at distance_matrix.js:4
        at Lp.o (distance_matrix.js:3)
        at Object.c [as _qeep52] (common.js:60)
        at DistanceMatrixService.GetDistanceMatrix?1m3&1m2&1d21.3327483&2d-157.8617057&2m3&1m2&1d45.524074&2d-122.700498&2m3&1m2&1d45.54798&2d-122.590283&2m3&1m2&1d45.400129&2d-122.737195&2m3&1m2&1d45.476286&2d-122.823794&2m3&1m2&1d45.336946&2d-122.591343&2m3&1m2&1d47.446484&2d-122.152732&2m3&1m2&1d47.820441&2d-122.267834&2m3&1m2&1d47.618114&2d-122.205874&2m3&1m2&1d47.679808&2d-122.323764&2m3&1m2&1d47.407714&2d-122.299158&2m3&1m2&1d43.103436&2d141.365886&2m3&1m2&1d43.103436&2d141.365886&2m3&1m2&1d35.6671&2d139.777066&3e0&6sen-US&7e0&callback=_xdc_._qeep52&key=AIzaSyC2QAcz4Y1MAWXMYb6xhKQBWShUnxjrTmc&token=111597:1

Here is some data from my JSON file.

    "type": "FeatureCollection",
    "features": [{
            "geometry": {
                "type": "Point",
                "coordinates": [-122.700498,45.524074
            "type": "Feature",
            "properties": {
                "category": "covid-test-site",
                "hours": "8am-8pm Mon-Fri, 9am-6pm Sat/Sun",
                "description": "Schedule your appointment within 72 hours of departure. We recommend planning ahead when scheduling to guarantee availability.Ask for the Rapid RNA Molecular test when you arrive for your appointment.Get your printed results and enjoy your trip!",
                "test": "Rapid RNA Molecular",
                "cost": "$199",
                "name": "AFC Urgent Care NW Portland",
                "phone": "(503) 305-6262",
                "address": "25 NW 23rd Place,Portland,OR 97210,United States ",
                "website": "https://afcurgentcareportland.com/traveling-hawaii",
                "storeid": "01"