简体   繁体   English

谷歌地图:如何使用自定义叠加创建自定义信息窗口

[英]Google map : How to create a custom infowindow used custom overlay

i'm a newbie in javascript我是 JavaScript 新手

use custom overlay but always detect 'cannot read property 'setContent' of undefined'使用自定义叠加但始终检测到“无法读取未定义的属性“setContent””

my javascript code is https://github.com/SaneMethod/CGWin/blob/master/src/cGWin.js我的 javascript 代码是https://github.com/SaneMethod/CGWin/blob/master/src/cGWin.js

and i use jquery because of parsing Exel file我使用 jquery 因为解析 Exel 文件

////https://github.com/SaneMethod/CGWin/blob/master/src/cGWin.js/////
function  GenCustomWindow () {
    var CustomWindow = function () {
    ....
    }
}
////parsing code////
$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "",
        datatype: "text",
        success: function (data) { processData(data); }
    });
});    
function processData(allText) {
        ....
    var info = new GenCustomWindow();
    for(i = 0;i < name.length;i++)
    {
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(a, b),
            map: map,
            icon: markerImage,
            optimized: false
        });            
        google.maps.event.addListener(marker, 'click', (function (marker, i) {
            return function () {
                content =
                    '<div class="iw-title">' +
                    name[i] + '</div>' +
                    '<div class="iw-content">' +
                    '<div class="iw-subTitle">' + add[i] + '</div>' +
                    '</div>' +
                    '<div class="iw-bottom-gradient"></div>' +
                    '</div>';
                info.CustomWindow.setContent('content');
            }
        })(marker, i));
    }
}

there is always error in info.CustomWindow.setContent info.CustomWindow.setContent 总是有错误

why is this code an error?为什么这段代码是错误的?

and can you recommend another custom infowindow?你能推荐另一个自定义信息窗口吗?

GenCustomWindow() returns a CustomWindow , which means info is alread a CustomWindow . GenCustomWindow()返回一个CustomWindow ,这意味着info已经是一个CustomWindow

Change改变

info.CustomWindow.setContent('content');

to

info.setContent('content');

And everything should work fine.一切都应该正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM