1
Personal talk,
I’m having trouble integrating Google maps into React. I saw many people with this doubt, although the documentation of the api is quite complete, most of the examples I saw are within the class model or using some third party library.
Someone who has already had this experience has done it using pure Javascript?
Follow the code of my component:
import React from 'react';
const OverviewMap = () => {
const script = document.createElement('script');
script.defer = true;
script.src = 'https://maps.googleapis.com/maps/api/js?key=CHAVE_AQUI'
document.head.appendChild(script)
const map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
})
return (
<>
<h1>Olá mundo!</h1>
<div id='map'>
{map}
</div>
</>
);
};
export default OverviewMap;
How to make the map instantiated when the page loads? And why do I have this error 'cannot find name google'?
noted the example I posted?
– novic
@Virgilionovic yes, I just read friend! I managed to render the map after some effort, thank you! : D. I found libraries a little unstable, including maintenance problems. I preferred to use something more generic, although it is more verbose, right?
– Curi