Last active
March 23, 2017 16:29
-
-
Save saifazmi/be7ac94498e5b9cf8874c241e2211ab6 to your computer and use it in GitHub Desktop.
Snippet: JS function to intialise a GMap with a marker and 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
function initMap() { | |
// Office lat lang | |
var officeLatLang = { | |
lat: -25.363, | |
lng: 131.044 | |
}; | |
// infoWindow content string | |
var infoContent = '<p>55 Dangal Road,<br>' + | |
'Vikas Nagar, Lucknow<br>' + | |
'Uttarpradesh, 226022<br>' + | |
'India</p>'; | |
// Initialise the infoWindow with the content string | |
var infowindow = new google.maps.InfoWindow({ | |
content: infoContent | |
}); | |
// Initialise the map with required options | |
var map = new google.maps.Map(document.getElementById('map'), { | |
zoom: 4, // map zoom level | |
center: officeLatLang, // coordinates to center on | |
scrollwheel: false // prevent accidental scrolling of map | |
}); | |
// Initialise the marker and add to map | |
var marker = new google.maps.Marker({ | |
position: officeLatLang, // marker coordinates | |
map: map // map to place on | |
}); | |
// Display infoWindow on marker click | |
marker.addListener('click', function() { | |
infowindow.open(map, marker); | |
}); | |
// Display infoWindow onLoad | |
infowindow.open(map, marker); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment