Skip to content

Instantly share code, notes, and snippets.

Created October 24, 2016 12:15
Show Gist options
  • Select an option

  • Save anonymous/bf504d975fbf950cc474943fc3a47d5d to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/bf504d975fbf950cc474943fc3a47d5d to your computer and use it in GitHub Desktop.
Google map
<html>
<head>
</head>
<body>
<h1>Map example</h1>
<div style="height: 500px;width: 100%" id="map-canvas"></div>
<script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?v=3.26'></script>
<script>
(function () {
'use strict';
var styles = [{
"featureType": "all",
"elementType": "labels.text.fill",
"stylers": [{"saturation": 36}, {"color": "#000000"}, {"lightness": 40}]
}, {
"featureType": "all",
"elementType": "labels.text.stroke",
"stylers": [{"visibility": "on"}, {"color": "#000000"}, {"lightness": 16}]
}, {
"featureType": "all",
"elementType": "labels.icon",
"stylers": [{"visibility": "off"}]
}, {
"featureType": "administrative",
"elementType": "geometry.fill",
"stylers": [{"color": "#000000"}, {"lightness": 20}]
}, {
"featureType": "administrative",
"elementType": "geometry.stroke",
"stylers": [{"color": "#000000"}, {"lightness": 17}, {"weight": 1.2}]
}, {
"featureType": "administrative",
"elementType": "labels",
"stylers": [{"visibility": "off"}]
}, {
"featureType": "landscape",
"elementType": "geometry",
"stylers": [{"color": "#000000"}, {"lightness": 20}]
}, {
"featureType": "landscape",
"elementType": "labels",
"stylers": [{"visibility": "off"}]
}, {
"featureType": "poi",
"elementType": "geometry",
"stylers": [{"color": "#000000"}, {"lightness": 21}]
}, {"featureType": "poi", "elementType": "labels", "stylers": [{"visibility": "off"}]}, {
"featureType": "road",
"elementType": "labels",
"stylers": [{"visibility": "off"}]
}, {
"featureType": "road.highway",
"elementType": "geometry.fill",
"stylers": [{"color": "#000000"}, {"lightness": 17}]
}, {
"featureType": "road.highway",
"elementType": "geometry.stroke",
"stylers": [{"color": "#000000"}, {"lightness": 29}, {"weight": 0.2}]
}, {
"featureType": "road.arterial",
"elementType": "geometry",
"stylers": [{"color": "#000000"}, {"lightness": 18}]
}, {
"featureType": "road.local",
"elementType": "geometry",
"stylers": [{"color": "#000000"}, {"lightness": 16}]
}, {
"featureType": "transit",
"elementType": "geometry",
"stylers": [{"color": "#000000"}, {"lightness": 19}]
}, {"featureType": "water", "elementType": "geometry", "stylers": [{"color": "#1b2a30"}, {"lightness": 17}]}];
var markers = [{
position: {
lat: -25.363, lng: 131.044
},
title: 'Title 1',
infoWindowText: '<h3>Test</h3><br><a href="https://google.com">Click here</a>'
},
{
position: {
lat: -20.363, lng: 100.044
},
title: 'Title 2',
infoWindowText: '<h3>Test 2</h3><br><a href="https://bing.com">Click here</a>'
}];
function loadGoogleMap() {
var mapCenter = new google.maps.LatLng(0, 0);
var mapOptions = {
zoomControl: false,
mapTypeControl: false,
streetViewControl: false,
scrollwheel: false,
draggable: false,
center: mapCenter,
zoom: 2,
styles: styles,
fullscreenControl: false
};
var map = new google.maps.Map(mapCanvas, mapOptions);
markers.forEach(function (item) {
var marker = new google.maps.Marker({
position: item.position,
map: map,
optimized: false,
title: item.title,
//icon: 'http://example.com/asdsa.png'
});
var infoWindow = new google.maps.InfoWindow({content: item.infoWindowText});
google.maps.event.addListener(map, 'click', function () {
infoWindow.close();
});
google.maps.event.addListener(marker, 'click', function () {
infoWindow.open(map, marker);
marker.setAnimation(null);
});
});
var timeout;
/**
* Resize event handling, make map more responsive
* Center map after 300 ms
*/
google.maps.event.addDomListener(window, 'resize', function () {
if (timeout) {
clearTimeout(timeout);
}
timeout = window.setTimeout(function () {
map.setCenter(mapCenter);
}, 300);
});
}
var mapCanvas = document.getElementById('map-canvas');
if (typeof mapCanvas !== 'undefined') {
if (typeof google == 'object' && google.maps) {
google.maps.event.addDomListener(window, 'load', loadGoogleMap)
}
else {
mapCanvas.innerHTML = '<p class="map-not-loaded" style="text-align: center">Failed to load Google Map.<br>Please try again.</p>';
mapCanvas.style.height = 'auto';
}
}
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment