var markers = [];
var infowindow = new google.maps.InfoWindow();
var map
var pointerObj = [{
acLatitude: "34.005723",
acLongitude: "-84.23386",
name: "xyz",
address: "abc",
icon:"/img/as.jpg"
},
{
acLatitude: "34.005723",
acLongitude: "-84.23386",
name: "xyz",
address: "abc",
icon:"/img/as.jpg"
},
{
acLatitude: "34.005723",
acLongitude: "-84.23386",
name: "xyz",
address: "abc",
icon:"/img/as.jpg"
},
{
acLatitude: "34.005723",
acLongitude: "-84.23386",
name: "xyz",
address: "abc",
icon:"/img/as.jpg"
}
];
function initMapObj() {
map = new google.maps.Map(document.getElementById("googleMap"), {
zoom: 16,
center: new google.maps.LatLng(34.005813, -84.32682),
mapTypeId: "roadmap",
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
position: google.maps.ControlPosition.TOP_RIGHT
},
zoomControl: true,
zoomControlOptions: {
position: google.maps.ControlPosition.RIGHT_BOTTOM
},
scaleControl: true,
streetViewControl: true,
streetViewControlOptions: {
position: google.maps.ControlPosition.RIGHT_BOTTOM
},
fullscreenControl: true
});
}
function bindMarkers() {
var bounds = new google.maps.LatLngBounds();
for (var key in pointerObj) {
var arrObj = pointerObj[key];
latLongCollection.push({
position: new google.maps.LatLng(arrObj.acLatitude, arrObj.acLongitude),
name: arrObj.name,
address: arrObj.address,
});
}
latLongCollection.forEach(function (pointerDtl) {
var marker = new google.maps.Marker({
position: pointerDtl.position,
icon: pointerDtl.icon,
map: map
});
markers.push(marker);
bounds.extend(marker.position); //center the map respective of all the points
google.maps.event.addListener(marker, "mouseover", (function (mm, tt) { //can be changed with 'click' event
return function () {
var infoContent = '<div class="infowindow">';
infoContent += '<div class="point-name">'+pointerDtl.catName+'</div>';
infoContent += '<div class="point-address">' + pointerDtl.address + '</div>';
infoContent += "</div>";
infowindow.setOptions({
content: infoContent
});
infowindow.open(map, mm);
};
})(marker, pointerDtl.address));
});
map.fitBounds(bounds) //center the map respective of all the points
}