0

I am having trouble on getting the latitude , what i've tried so far is searchLocation.findLocationByAddress.geoCode.latitude and i get this error

error

LocationAdd.js:288 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'latitude')

here is my code

 const { data: searchLocation } = await getLocations({
    variables: {
      placeSearch: {
        address: value
      },
    },
  });
  console.log(searchLocation.findLocationByAddress)
  geoCode = {
    latitude: searchLocation.findLocationByAddress.geoCode.latitude,
    longitude: searchLocation.findLocationByAddress.geoCode.longitude,
  };

enter image description here

0

1 Answer 1

1

findLocationByAddress returns an array, I think you should call .map() or access an element with [].

Sign up to request clarification or add additional context in comments.

1 Comment

how? like this 'searchLocation.map((item) => geoCode ={latitude: item.geoCode.latitude, longitude: item.geoCode.longitude})' ? may i see your answer with code please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.