0

I'm working for the first time with axios. I'm writing a function getLatLngByZipcode which when called will return an object containing the latitudes and the longitudes of a place based on the zip code provided. Please help!

  function getLatLngByZipcode(zipcode) {
    const params = {
      auth: "MY API KEY ",
      locate: zipcode,
      json: "1"
    };
    axios
      .get("https://geocode.xyz", { params })
      .then((response) => {
        //response.data.latt --> latitude
        //response.data.longt --> longitude
        
        //How do I return an object which contains both latitude and longitude like: 

        // {
        //   latitude : response.data.latt,
        //   longitude: response.data.longt
        // }

      })
      .catch((error) => {
        console.log(error);
      });
  }

  let CoordinateObj = getLatLngByZipcode(144001);

0 Answers0