Map Simple

by johannpickard

HTML

<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBrgGGbiHgV4n7ykSNmc8ZpxBv2HIbe2xg&callback=initMap" async defer></script>

CSS

/* 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;
}

JavaScript

var map;
function initMap() {

var LatitudeSet = getUrlParameter('latitude');
var LongitudeSet = getUrlParameter('longitude');


  map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.012665 , lng: 18.450436},
    zoom: 17
  });
}




var getUrlParameter = function getUrlParameter(sParam) {
// this part I added, which uses the string from stuff after the hash instead of the stuff after the ? lik usual. This is so that it works on s3. Which the ? does not
    var sPageURL = window.location.hash.substr(1),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
        }
    }
};