javascript - Google Maps - Cannot read property 'offsetWidth' of null -
i've read few articles on this, can't figure out. one tried initialize killed map, white screen appeared.
the error appears in console on page except contact page, page map.
this code in javascript:
var latlng = new google.maps.latlng(0, 0); var myoptions = { zoom: 14, center: latlng, scrollwheel: false, disabledefaultui: true, draggable: false, keyboardshortcuts: false, disabledoubleclickzoom: false, noclear: true, scalecontrol: false, pancontrol: false, streetviewcontrol: false, styles: [{"featuretype":"landscape","stylers":[{"hue":"#ffbb00"},{"saturation":43.400000000000006},{"lightness":37.599999999999994},{"gamma":1}]},{"featuretype":"road.highway","stylers":[{"hue":"#ffc200"},{"saturation":-61.8},{"lightness":45.599999999999994},{"gamma":1}]},{"featuretype":"road.arterial","stylers":[{"hue":"#ff0300"},{"saturation":-100},{"lightness":51.19999999999999},{"gamma":1}]},{"featuretype":"road.local","stylers":[{"hue":"#ff0300"},{"saturation":-100},{"lightness":52},{"gamma":1}]},{"featuretype":"water","stylers":[{"hue":"#0078ff"},{"saturation":-13.200000000000003},{"lightness":2.4000000000000057},{"gamma":1}]},{"featuretype":"poi","stylers":[{"hue":"#00ff6a"},{"saturation":-1.0989010989011234},{"lightness":11.200000000000017},{"gamma":1}]}], maptypeid: google.maps.maptypeid.roadmap }; var map = new google.maps.map(document.getelementbyid("map"), myoptions); var geocoder_map = new google.maps.geocoder(); var address = '11681 king fahd road, al mohammadiyah, 4047, riyadh, riyadh province saudi arabia'; geocoder_map.geocode({ 'address': address }, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setcenter(results[0].geometry.location); var image = "../wp-content/themes/rawafid-systems/assets/img/pin.svg"; var marker = new google.maps.marker({ map: map, icon: image, position: map.getcenter() }); var contentstring = 'tagline'; var infowindow = new google.maps.infowindow({ content: contentstring }); // google.maps.event.addlistener(marker, 'click', function() { // infowindow.open(map, marker); // }); } else { alert("geocode not successful following reason: " + status); } });
html
<?php $location = get_field('map_location'); if( !empty($location) ): ?> <div id="map" class="acf-map featured-banner-container"> <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div></div> <?php endif; ?>
the above code being used on template file contact page using. can guess somehow keeps looking find on other pages , that's why errors. not sure.
nowhere in here mentions "offsetwidth". in console says it's coming from:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
any ideas need modify in javascript? have file loaded in footer, if matters.
Comments
Post a Comment