0

Google map started throwing 'Uncaught TypeError: Cannot read property 'lat' of null ' error when I added preserveViewport:true to the kmlLayer options based on this stackoverflow question.

Here's the fiddle: http://jsfiddle.net/svp70tjx/1/

html:

<div id="map"></div>

javascript:

function initialize() {
            var mapOptions = {
                scrollwheel: false,
                zoom: 11,
                center: google.maps.LatLng(41.875696,-87.624207),
                styles: [{"featureType":"administrative","elementType":"all","stylers":[{"visibility":"on"},{"saturation":-100},{"lightness":20}]},{"featureType":"road","elementType":"all","stylers":[{"visibility":"on"},{"saturation":-100},{"lightness":40}]},{"featureType":"water","elementType":"all","stylers":[{"visibility":"on"},{"saturation":-10},{"lightness":30}]},{"featureType":"landscape.man_made","elementType":"all","stylers":[{"visibility":"simplified"},{"saturation":-60},{"lightness":10}]},{"featureType":"landscape.natural","elementType":"all","stylers":[{"visibility":"simplified"},{"saturation":-60},{"lightness":60}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"},{"saturation":-100},{"lightness":60}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"off"},{"saturation":-100},{"lightness":60}]}],
                zoomControlOptions: {
                    style: google.maps.ZoomControlStyle.SMALL
                }
            }

            var map = new google.maps.Map(document.getElementById('map'), mapOptions);

            var ctaLayer = new google.maps.KmlLayer(
                'https://maps.google.com/maps/ms?msa=0&msid=209537462410499505635.0004d278fb32588bd6da3&ie=UTF8&t=h&ll=48.985492,18.191269&spn=0.27644,0.427604&output=kml',
                {
                    suppressInfoWindows: true,
                    map: map,
                    preserveViewport: true
                }
            );
            ctaLayer.setMap(map);
        }

        google.maps.event.addDomListener(window, 'load', initialize);
Community
  • 1
  • 1
Matthew Abrman
  • 711
  • 10
  • 18

1 Answers1

0

nevermind, the map stopped using the center from the KML and went to the mapOptions where it's

center: google.maps.LatLng(41.875696,-87.624207),

had to change it to

center: new google.maps.LatLng(41.875696,-87.624207),
Matthew Abrman
  • 711
  • 10
  • 18