0

Currently I am using tag to show marker instead of this I want to show custom html design to marker.

Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225

1 Answers1

0

GoogleMap API defines a MarkerWithLabel component which can be passed to the GoogleMap component. Here is an example

<GoogleMap
defaultZoom={8}
defaultCenter={{ lat: -34.397, lng: 150.644 }}>

    <MarkerWithLabel
      position={{ lat: -34.397, lng: 150.644 }}
      labelAnchor={new google.maps.Point(0, 0)}
      labelStyle={{backgroundColor: "yellow", fontSize: "32px", padding: "16px"}}
    >
      <CustomizedMarker />
    </MarkerWithLabel>
</GoogleMap>

You can add label to Marker by separating marker's markup in separate component like this:

class CustomizedMarker extends Component{
constructor(props){
    super(props)
    this.state = {
    labelHidden : true
    }
}
toggleLabel = ()=>{
    this.setState({
        labelHidden: !this.state.labelHidden
    })
}
render(){
    return(
        <div onClick={this.toggleLabel}>
            <p>Hello World</p>
            <h5 hidden={this.state.labelHidden}>Your Label</h5>
        <div>
    )
}
}

You can view the complete reference here

saim2025
  • 280
  • 2
  • 5
  • 14