//Do maps exist?
if ($(".js-map").length) {
$(function() {
//Stylers array
var styles = [];
// Render to
$maps = $('.js-map');
$maps.each(function(index, Element) {
$vcardGmap = $(Element).children('.vcard-gmap');
// Map vars
var map;
var geocoder;
var marker;
var infowindow;
var address =
$vcardGmap.children('.address').text() + ', '
+ $vcardGmap.children('.city').text() + ', '
+ $vcardGmap.children('.state').text() + ' '
+ $vcardGmap.children('.zip').text() + ', '
+ $vcardGmap.children('.country').text();
//Info Window Content
var content =
$vcardGmap.children('.location').text() + '
' +
$vcardGmap.children('.address').text() + '
' +
$vcardGmap.children('.city').text() + ' ' +
$vcardGmap.children('.state').text() + ' ' +
$vcardGmap.children('.zip').text();
//If available, add a phone number to the info window
if (0 < $vcardGmap.children('.phone').text().length) {
content += '
' + $vcardGmap.children('.phone').text();
}
geocoder = new google.maps.Geocoder();
// Geocode the Address
geocoder.geocode({'address': address}, function(results, status) {
// Status check
if (status === google.maps.GeocoderStatus.OK) {
vcardGmapOptions.center = results[0].geometry.location;
map = new google.maps.Map(Element, vcardGmapOptions);
// Custom Marker options
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
animation: google.maps.Animation.DROP,
//icon: 'images/yourdopemarker.png',
title: $vcardGmap.children('.location').text()
});
//Create tile/info window
infowindow = new google.maps.InfoWindow({'content': content});
google.maps.event.addListener(map, 'tilesloaded', function(event) {
infowindow.open(map, marker);
});
//Click marker to open tile
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
//Center on Resize
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
} else {
// Alert if map fails
alert('damn, the google maps failed yo: ' + status);
}
});
/*----------------------------------------------
--Control Options
----------------------------------------------- */
var vcardGmapOptions = {
//Let's establish zoom control in our vcard markup
'zoom': parseInt($vcardGmap.children('.zoom').text()),
'mapTypeId': google.maps.MapTypeId.ROADMAP,
'mapTypeControl': false,
'scrollwheel': false,
'disableDefaultUI': false,
'styles': styles
};
});
});
}