Skip to content

Cannot read property 'latLng' of undefined #767

@tonystaark

Description

@tonystaark

Hello I am trying to map through the markers to create multiple markers but have the following problem
cannot

Below is my code:

 this.state = {
  lat: 1.3521,
  lng: 103.8198,
  zoom: 11,
  addLat: 1.3521,
  addLng: 103.8198,
  data:[  
    {  
     "latitude":"1.3589783333",
     "is_on_trip":false,
     "id":5,
     "longitude":"103.752293000"
    },
    {  
     "latitude":"1.3492333333",
     "is_on_trip":true,
     "id":6,
     "longitude":"103.729582"
    },
    {  
     "latitude":"1.2894376666",
     "is_on_trip":true,
     "id":8,
     "longitude":"103.812434499"
    },
  ]
}

render() {
  const { lat, lng, zoom } = this.state;
  const Markers = this.state.data > 0 ? this.state.data.map(d => (
    <Marker key = {d.id}
      lat = {d.latitude}
      lng = {d.longitude}
      text="my marker"
      fontColor="red"
    />
  )) : 'Loading'

return (
  <div style={{ height: '100vh', width: '100%' }}>
    <GoogleMapReact
      bootstrapURLKeys={{ key: 'AIzaLyDEpqWPsg8vLUgdVdmzHKuZWW45h3mtZTI' }}  (fake!!)
      defaultCenter={{lat, lng}}
      center={[this.state.addLat, this.state.addLng]}
      defaultZoom={zoom}
      // onGoogleApiLoaded={({payload}) => this.redraw(payload)}
    >
      {Markers}
    </GoogleMapReact>
  </div>
)

}

Cant figure out why cant I map through the markers. Anyone can help? Or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions