小编Kus*_* Rr的帖子

"未捕获的TypeError:无法在'Window'上执行'getComputedStyle':当gmap添加时,参数1的类型不是'Element'.Tq ​​@ VM107:37mF

我是新手,练习HTML和jquery.有人可以帮我解决这个错误吗?当我试图动态添加谷歌地图时,我收到一个错误,如未捕获的类型错误:未能在'window':参数上执行'getComputedStyle'.

html标记是:

<type="submit" id="locate">Find me</button>
<div id="gmap"> </div>

enter code here

    $(document).ready(function () {

        $('#locate').on('click', function (e) {
            e.preventDefault();
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(showPosition);
            }
            else {
                console.log('Geolocation is not supported by your browser');
            }
        });
        var latlng,
         mapOptions,
         map;

        showPosition = function (position) {
            latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude)
            mapOptions = {
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                zoom: 15
            }
            Map = new google.maps.Map($('#gmap'), mapOptions);
            var marker = new google.maps.Marker({
                position: latlng,
                map: map,
                title: "You are here"
            })
       }
    });
Run Code Online (Sandbox Code Playgroud)

html jquery google-maps

6
推荐指数
1
解决办法
9266
查看次数

标签 统计

google-maps ×1

html ×1

jquery ×1