JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,places&ext=.js"></script>
<div id="map" style="height:100%"></div>
CSS
html, body {
height: 100%;
margin: 0;
padding: 0;
}
JavaScript
google.maps.visualRefefresh = true;
var map;
function initialize() {
getCoordinates('287 West Center Street Utah', function (coords) {
var mapOptions = {
center: new google.maps.LatLng(coords[0], coords[1]),
zoom: 8
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
})
}
google.maps.event.addDomListener(window, 'load', initialize);
var geocoder = new google.maps.Geocoder();
function getCoordinates(address, callback) {
var coordinates;
geocoder.geocode({
address: address
}, function (results, status) {
coords_obj = results[0].geometry.location;
coordinates = [coords_obj.lat(), coords_obj.lng()];
callback(coordinates);
})
}