'get location before map loaded problem react native

I have created get location function that triggered before map is loaded on class with componentDidMount.

When I rebuild or refresh the app it wont give me the location (and throws me errors with map size cant be 0 or some other errors with Airmap).

When I save some change on the code and it saves, the get location triggered well and it works fine.

My map is in component, I tried to trigger the get location function in onLoad and at isMapReady function but same error.

another try: I tried to rerender untill there get actually worked - sometimes it worked when refreshed few times and sometimes not: this.props.choosenLocation? console.log("location") : this.props.getCurrentLocation() in render method.

Please I googled anywhere and cant find a solution for that. As far as I understand its because the location not provided before map loaded.

My code:

 async componentDidMount(){
..
        await this.props.getCurrentLocation();
...   

render(){

        this.props.choosenLocation? console.log("location: " ,this.props.selectedAddress): this.props.getCurrentLocation();      
...
    }
return(
 map container..
..
)

Is there a problem with the emulator that is slow down while reloading or am I missing some workaround?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source