score:0

Accepted answer
const state = {
  places: [
    {
      site_id: "1",
      latitude: 40.76347,
      longitude: -73.929032
    },
    {
      site_id: "2",
      latitude: 40.601,
      longitude: -73.9643
    }
  ],
  location: {
    latitude: 40.8019,
    longitude: -73.9786
  }
};

const calculateDistance = (start_x, start_y, end_x, end_y) => {
  try {
    let distance = getDistance( // <-- not async function, no need to await
      {
        latitude: start_x,
        longitude: start_y
      },
      {
        latitude: end_x,
        longitude: end_y
      }
      //(accuracy = 100)
    );
    return distance;
  } catch (error) {
    console.log(error);
  }
};

const map1 = state.places.map((place) => ({
  ...place,
  distance: calculateDistance(
    place.latitude,
    place.longitude,
    state.location.latitude,
    state.location.longitude
  )
}));

console.log(JSON.stringify(map1));

Related Query

More Query from same tag