Last active
March 8, 2021 19:15
-
-
Save JonCatmull/8a7ac09388fc9d616cfd to your computer and use it in GitHub Desktop.
Google maps with class and data attributes
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
<div id="map-canvas-footer" style="height:300px; width:100%;" class="gMap" data-lat="<?php echo $location['lat']?>" data-lng="<?php echo $location['lng']?>"></div> |
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(){ | |
function initialize(e) { | |
var $map = $(e); | |
var myLatlng = new google.maps.LatLng($map.data('lat'), $map.data('lng')); | |
var mapOptions = { | |
zoom: 17, | |
center: myLatlng, | |
// draggable: false, | |
disableDefaultUI: true, | |
scrollwheel: false, | |
disableDoubleClickZoom: true | |
}; | |
var map = new google.maps.Map(e, mapOptions); | |
var image = '../images/icon.png'; | |
var marker = new google.maps.Marker({ | |
position: myLatlng, | |
map: map, | |
icon: image | |
}); | |
if ($map.data('infowindow') == true){ | |
var contentString = '<div id="map-content">'+ | |
'<div id="siteNotice">'+ | |
'</div>'+ | |
'<h2 id="firstHeading" class="firstHeading">Vision Profiles</h2>'+ | |
'<div id="bodyContent">'+ | |
'<p>Unit K, Quedgeley Trading Estate, Bristol Road,<br>' + | |
'Hardwicke, Gloucestershire, GL2 4PA</p>'+ | |
'<a href="/">Get Directions</a>'+ | |
'</div>'+ | |
'</div>'; | |
var infowindow = new google.maps.InfoWindow({ | |
content: contentString, | |
pixelOffset: new google.maps.Size(210, 100) | |
}); | |
infowindow.open(map,marker); | |
} | |
} | |
$('.gMap').each(function(i,e) { | |
google.maps.event.addDomListener(window, 'load', initialize(e)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you inspected the lat and lng properties for myLatlng should they have length values of zero?