Skip to content

Instantly share code, notes, and snippets.

@rintoug
Created March 25, 2017 15:54
Show Gist options
  • Save rintoug/bafefad64d629f835641652d66653799 to your computer and use it in GitHub Desktop.
Save rintoug/bafefad64d629f835641652d66653799 to your computer and use it in GitHub Desktop.
Google map with markers and popup
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html {
height: 100%
}
body {
height: 100%;
margin: 0;
padding: 0
}
#map-canvas {
height: 400px;
width: 400px;
}
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=YourAPIKey&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!'
});
var infowindow = new google.maps.InfoWindow({
content: 'test: '
});
makeInfoWindowEvent(map, infowindow, marker);
}
function makeInfoWindowEvent(map, infowindow, marker) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment