Skip to content

Instantly share code, notes, and snippets.

@ZachMoreno
Last active December 24, 2015 20:03
Show Gist options
  • Save ZachMoreno/6e891b6c7487380b69d6 to your computer and use it in GitHub Desktop.
Save ZachMoreno/6e891b6c7487380b69d6 to your computer and use it in GitHub Desktop.
Wrapper function to create a Google Map with a single marker, including optional click event handler
function newMap(lat, long, zoom, domID, clickHandler) {
var latLong = new google.maps.LatLng(lat,long),
options = {
center: {
lat : lat,
lng : long
},
// set base map
mapTypeId: google.maps.MapTypeId.TERRAIN,
// set base map custom styles
styles: mapStyles,
zoom: zoom,
scrollwheel: false,
mapTypeControl: false,
streetViewControl: false
},
map = new google.maps.Map(document.getElementById(domID), options);
var marker = new google.maps.Marker({
position : latLong,
map : map,
icon : 'http://maps.google.com/mapfiles/ms/icons/blue.png',
title : ''
});
if(clickHandler) {
google.maps.event.addListener(marker, 'click', (function(marker) {
return (function() {
clickHandler();
})();
}));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment