Skip to content

Instantly share code, notes, and snippets.

@JonCatmull
Last active March 8, 2021 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonCatmull/8a7ac09388fc9d616cfd to your computer and use it in GitHub Desktop.
Save JonCatmull/8a7ac09388fc9d616cfd to your computer and use it in GitHub Desktop.
Google maps with class and data attributes
<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>
$(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));
});
});
@winkylocc
Copy link

When you inspected the lat and lng properties for myLatlng should they have length values of zero?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment