Mathis Giovannetti
Mathis Giovannetti

Reputation: 5

expo Location.reverseGeocodeAsync issue

location to get the coordinate of the user, and to know the address which coordinate refer to:

But I Don't understand something this is my a part of my code:

const AdressWithCoordonate = async (coordinate) => {
    try {
      let result = await Location.reverseGeocodeAsync(coordinate);
      return result[0];
    } catch (e) {
      console.log(e);
    }
  };

const mapHandlePress = (coordinates) => {
    let arrayMarkers = [...markers];
    arrayMarkers.push({
      id: arrayMarkers.length + 1,
      coordinate: coordinates,
      address: AdressWithCoordonate(coordinates),
      title: "test",
      description: "test2",
    });
    console.log(arrayMarkers);
    setMarkers(arrayMarkers);
    console.log(markers);
  };

And when I see the value inside the address prop I see something like this:

Object {
    "address": Promise {
      "_40": 0,
      "_55": Object {
        "city": "San Francisco",
        "country": "United States",
        "isoCountryCode": "US",
        "name": "980 Green St",
        "postalCode": "94133",
        "region": "CA",
        "street": "Green St",
      },
      "_65": 1,
      "_72": null,
    },

(I didn't forgot to ask the Location permissions)

I don't know how to resolve this, help me please. Thanks

Upvotes: 0

Views: 1050

Answers (1)

bas
bas

Reputation: 15722

Try something like this:

const mapHandlePress = (coordinates) => {
  AdressWithCoordonate(coordinates).then((res) => {
    let arrayMarkers = [...markers];
    arrayMarkers.push({
      id: arrayMarkers.length + 1,
      coordinate: coordinates,
      address: res,
      title: 'test',
      description: 'test2',
    });
    console.log(arrayMarkers);
    setMarkers(arrayMarkers);
    console.log(markers);
  });
};

This way you actually pass the result of the asynchronous operation instead of the entire Promise object.

Upvotes: 1

Related Questions