question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google map get refresh when click on marker to open infowindo

See original GitHub issue

I have an issue with react-google-maps. When i click on a marker so infowindo opens but the google map get refresh, it reset its default zoom. but i want if any user make zoom map and then click marker so map should not reset with its default zoom , it should stay zoom which user make to see marker. Simply i want that map should not refresh after click on marker

here is code class Map extends Component { constructor(props) {

  super(props);
 
  this.state = {
    showm:''
    
  }
}



handleToggleOpen (id) {

  this.setState({
    showm:id
  });
}

handleToggleClose () {
  this.setState({
    showm:''
  });
}

render() { const GoogleMapExample = withGoogleMap(props => ( <GoogleMap defaultCenter = { { lat: 40.752307, lng: -73.912304 } } defaultZoom = { 10 } > {this.props.information.map(marker => (

        <Marker
          position={{ lat: parseFloat(marker.latitude) , lng:parseFloat(marker.longitude)  }}
          
          onClick={() => this.handleToggleOpen(marker.id)}
        >
          {
        this.state.showm === marker.id &&
       <InfoWindow onCloseClick={this.props.handleCloseCall} defaultOptions= {{ position: [parseFloat(marker.latitude) ,parseFloat(marker.longitude)] }}>
          <div style={{width:'300px' }}>
            <table>
            <tr>
              <td>
                <div className="" style={{padding:'0px' }}>
                  <img style = {{width:'100%','margin-top':'0px'}} alt="" src={"public/uploads/profile_image/" + marker.image} />
                </div>
              </td>
              <td>&nbsp;&nbsp;&nbsp;</td>
              <td>
                <div className="" style={{'margin-top':'7px' }}>
                  <p>Name:{marker.shop_name}</p>
                  <p>Distance:{marker.distance.toFixed(2)}</p>
                  <p>Address:{marker.address}</p>
                </div>
              </td>
            </tr>
            </table>
            
            
          </div>
         
       </InfoWindow>
      }
        </Marker>

    ))}

    
  	
  </GoogleMap>

)); return( <div> <GoogleMapExample containerElement={ <div style={{ height: 650px, width: ‘500px’ }} /> } mapElement={ <div style={{ height: 100% }} /> } /> </div> ); } };

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

9reactions
nicolasardcommented, Oct 16, 2018

Hello!, i was following an example in the doc (https://tomchentw.github.io/react-google-maps/) and i found a way to fix the issue that i had about the reload of the whole map, i wrote my own example in https://codesandbox.io/s/q4vnjyknmj i was declaring the MyMapComponent inside the class, when i move it outside the map area stop to reload after a setState(). Hope this help you. @kapilideal @themakerman

1reaction
pestacommented, Dec 6, 2019

thanks @nicolasard that fixed it for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to refresh content of already open infowindow of google ...
Based from this tutorial, you have to close the info window first to be able to refresh its content. See Modifying content within...
Read more >
Info Windows | Maps JavaScript API - Google Developers
One way of retrieving a LatLng is by using the Geocoding service. Opening an info window on a marker will automatically update the...
Read more >
Simple Google Map with two Markers with InfoWindows
Update InfoWindow contents when marker is clicked. This is useful when content of infoWindow changes frequently. Enter some text in text box and...
Read more >
Bug: InfowWindow.setContent() from domready event does ...
1) Add a "domReady" event to my infoWindow and set initial contents. 2) Issue an open() in subsequent processing relying on the listener...
Read more >
Refresh Google Map Markers at interval without page refresh ...
You need to bind the marker usingjquery AJAX and JavaScript setInterval to refresh at regular interval. Check this example. Now please take its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found