JSFiddle - React, Tailwind, and code Playground
by willystyle
HTML
<!DOCTYPE html>
<html>
<head>
<title>MUKiT</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.
var map, infoWindow, marker;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
disableDefaultUI: true,
center: {lat: -34.397, lng: 150.644},
zoom: 16
});
infoWindow = new google.maps.InfoWindow;
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
map.addListener('click', function(e) {
placeMarkerAndPanTo(e.latLng, map);
});
function placeMarkerAndPanTo(latLng, map) {
if (marker) marker.setMap(null);
marker = new google.maps.Marker({
position: latLng
});
marker.setMap(map);
map.panTo(latLng); }
}
else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow,...