Google Maps Uncaught TypeError: Cannot read property 'stack' of undefined

这一生的挚爱 提交于 2019-12-11 09:07:03

问题


I'm new to Google maps and I'm trying to set up a basic directions display. I basically do:

var Map = new google.maps.Map( Canvas[ 0 ], 
{
    center: { lat: -34.397, lng: 150.644 },
    zoom: 8
} );

var DService = new google.maps.DirectionsService();
var DDisplay = new google.maps.DirectionsRenderer();
DDisplay.setMap( Map );

As soon as I do DDisplay.setMap( Map ); Chrome shows an error in the console.

The error is:

Uncaught TypeError: Cannot read property 'stack' of undefined

I have tried including the script using the <script async defer> with a callback, using JQuery $.getScript and currently I have it in the head section of the web page with no callback, all give the same error.

The full code follows (Please ignore the pre-processor commands):

<div data-googleMap {if $ID}id="{$ID}"{/if}>
  <h3 class="ui-widget-header">{TEXT}Map{/TEXT}</h3>
    <div data-googleMapCanvas></div>
</div>

<script>

$( document ).ready( function()
{
    'use strict';
//  {if $ID}
    var GoogleMap = $( '#{$ID}' );
//  {else}
    var GoogleMap = $( 'div[data-googleMap]' );
//  {/if}
    var Map = null;
    var DService = null;
    var DDisplay = null;

    GoogleMap.resizable( { animate: true, animateDuration: 'fast' } ).on( 'resizestop', function()
    {
        setTimeout( function()
        {
            var Center = Map.getCenter();
            google.maps.event.trigger( Map, 'resize' );
            Map.setCenter( Center );
        }, 500 );
    } );

    GoogleMap.draggable( { handle:'h3', cursor: "move" } );

    var Canvas = GoogleMap.find( 'div[data-googleMapCanvas]' );
    Map = new google.maps.Map( Canvas[ 0 ], 
    {
        center: { lat: -34.397, lng: 150.644 },
        zoom: 8
    } );

    DService = new google.maps.DirectionsService();
    DDisplay = new google.maps.DirectionsRenderer();
    DDisplay.setMap( Map );
});
</script>

PS: It makes not difference if I use the JQuery UI functions or not. Also I have tried changing the version of Google Maps API, it also make no difference.

Terry

来源:https://stackoverflow.com/questions/33162062/google-maps-uncaught-typeerror-cannot-read-property-stack-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!