谷歌信息框位置

时间:2016-03-24 09:53:41

标签: javascript google-maps google-maps-api-3

我试图根据标记的latLng来定位我的infoBox,我尝试了位置(latLng),但没有用,我也不想对pixelOffset进行硬编码,因为它与标记不对应我也尝试过pixelOffset(latLng),getPosition和setPosition方法。

上述所有内容似乎都没有做到:/

Class01 one = new Class01 { Integer = 16 };
Class02 two = new Class02 { Integer = one.Integer };

Console.WriteLine("Class one: {0} -- Class two: {1}", one.Integer, two.Integer); 
// Prints: Class one: 16 -- Class two: 16

one.Integer++;

Console.WriteLine ("Class one: {0} -- Class two: {1}", one.Integer, two.Integer); 
// Prints:             Class one: 17 -- Class two: 16
// I want it to print: Class one: 17 -- Class two: 17

这似乎工作正常

/"id":"(\d*\w*)"/i

1 个答案:

答案 0 :(得分:0)

循环遍历data数组,创建标记 每次,您重新初始化infobox变量以使用当前标记的位置 在循环结束时,您有一个名为infobox的变量,其中包含最后一个标记的位置。

当您点击任何标记时,它会在该位置打开该信息框。不是您创建标记时重新创建的信息框变量的第n次迭代的位置。

您需要做的就是在事件监听器中设置信息框的位置。

for (var i = data.length - 1; i >= 0; i--){
    var Lat = data[i].Item.Coordinate.Lat;
    var Lon = data[i].Item.Coordinate.Lon;
    var LatLon = new gm.LatLng(jobLat, +jobLon);

    var marker = new gm.Marker({
        position: LatLon,
        map: map,
        visible: true
    });

    var infobox = new InfoBox();

    marker.newContent = document.getElementById("infobox_"+data[i].Item.Id);

    gm.event.addListener(marker, 'click', (function (marker) {
        return function (pin, suppressInfoWindow) {
            if (!suppressInfoWindow) {
                    infobox.setContent(marker.newContent);
                    infobox.setPosition(marker.getPosition());
                    infobox.open(map, marker);
            }
    }
}
resultMarkers.push(marker);
相关问题