0

I was able to get the object containing the coordinates of the markers. However, when rendering it, I got the error as the title says.

try {
            const value = await AsyncStorage.getItem('@myData')
            if(value !== null) {
              const parseData = JSON.parse(value);
              const llat = parseFloat(parseData[0].location[0].lat);
              const llon = parseFloat(parseData[0].location[0].lon);
              const locs = parseData[0].location;
              const markersS = [];
              for (let i =0; i < locs.length; i++){
                    markersS.push({
                        coordinate: {
                           latitude: parseFloat(locs[i].lat),
                           longitude: parseFloat(locs[i].lon)
                        }
                    })
              }
              this.setState({
                lat : llat,
                lon :llon,
                region: {
                    latitude: llat,
                    longitude: llon,
                    latitudeDelta: 0.015,
                    longitudeDelta: 0.0121
                },
                location : locs,
                ready: true,
                markers: markersS
              },()=>{

                  alert(JSON.stringify(this.state.markers))

              })
            }
          } catch(e) {
            alert(e)
          }

Then render like this:

{this.state.ready && this.state.markers !=null && this.state.markers((item, index) => {
                    <Marker
                         coordinate = {item.coordinate}
                         pinColor = {'blue'}
                         description = {'Home Address'}
                     />

                    })
                }

I expect to load the markers on the map

1 Answer 1

1

Problems is with this.state.markers((item, index) => {. You should be using map function as below instead

this.state.markers.map((item, index) => {
...
Sign up to request clarification or add additional context in comments.

2 Comments

Oh, error is gone but markers are still not showing.
missed return statement. if you won't write return, you can write something like that: array.map(item => <Marker ... />) or: array.map(item => (<Marker ... />))

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.