Last active
February 7, 2019 13:27
-
-
Save nameDark/91efd38337d8f54781035e4ff4617619 to your computer and use it in GitHub Desktop.
Gmap. Adding few markers (with InfoWindow)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="map" style="height: 500px;"></div> | |
<script> | |
function initMap() { | |
var locations = [ | |
['InfoWindow Content', -33.890542, 151.274856,], | |
['InfoWindow Content', -33.923036, 151.259052,], | |
['InfoWindow Content', -34.028249, 151.157507,], | |
['InfoWindow Content', -33.800101, 151.287478,], | |
['InfoWindow Content', -33.950198, 151.259302,] | |
]; | |
var map = new google.maps.Map(document.getElementById('map'), { | |
zoom: 8, | |
center: {lat: -25.363, lng: 131.044}, | |
}); | |
var infowindow = new google.maps.InfoWindow(); | |
var marker, i; | |
for (i = 0; i < locations.length; i++) { | |
marker = new google.maps.Marker({ | |
position: new google.maps.LatLng(locations[i][1], locations[i][2]), | |
map: map | |
}); | |
google.maps.event.addListener(marker, 'click', (function(marker, i) { | |
return function() { | |
infowindow.setContent(locations[i][0]); | |
infowindow.open(map, marker); | |
} | |
})(marker, i)); | |
} | |
} | |
</script> | |
<script async defer src="https://maps.googleapis.com/maps/api/js?key=<?php echo $map_key ?>&language=en&callback=initMap"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment