JSFiddle - React, Tailwind, and code Playground
HTML
<div id="map">
</div>
<!-- Inserisci la tua api key nell'url -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=&callback=initMap">
</script>
CSS
#map {
width: 300px;
height: 300px;
}
JavaScript
function createMap(position) {
var myLatLng = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: myLatLng
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
}
function initMap() {
navigator.geolocation.getCurrentPosition(createMap);
}