I use google-map-react to display a Google Map with Custom Marker to show a location.
Can i change the location succesfully, its mean, passing lat and lng to the map component and put the marker on the new location, butthe view of the map its still on the older location.
How can i center on the new location?
Main Component
Lat and Lng starts with a coordinates, whit setState put a new
Don't put the entire component but it's the way I call the map
return (
<div className="main">
<div className="main__map">
<TheMap center={[this.state.lat, this.state.lng]} />
</div>
</div>
)
TheMap Component
import React,{useState , useEffect} from 'react';
import GoogleMapReact from 'google-map-react';
function TheMap(props){
const [cordinates , setCordinates] = useState(props);
const MyCustomMarker = () => <span class="material-icons">place</span>;
useEffect(() => {
setCordinates(props);
}, [props])
return(
<GoogleMapReact
yesIWantToUseGoogleMapApiInternals={true}
bootstrapURLKeys={{key:'THE KEY'}}
defaultZoom={16}
center={cordinates.center}
>
<MyCustomMarker
lat={cordinates.center[0]}
lng={cordinates.center[1]}
/>
</GoogleMapReact>
)
}
export default TheMap