【问题标题】:street view panorama in infowindows from database lat lng来自数据库 lat lng 的 infowindows 中的街景全景图
【发布时间】:2021-07-22 03:41:14
【问题描述】:

我想在从数据库创建的标记的信息窗口中显示街景全景。 下面的这段代码很好地显示了街景全景图,但只有数据库最后一行的 lat 和 lng。

$.ajax({
    url : 'category/subdi.php',
    async: true,
}).done(function(json){ 

  var data = JSON.parse(json);
  for(var i = 0; i < data.length; i++){

    var content = '<div id="content" style="width:500px;height:300px;"></div>';

    var infowindow = new google.maps.InfoWindow({
        content: content
    });
    
    var marker = new google.maps.Marker({
        position: {lat: parseFloat(data[i].subdi_lat), lng: parseFloat(data[i].subdi_long)},
        title: data[i].subdi_name,
        map: map
    }); 

    var pano = null;
    google.maps.event.addListener(infowindow, 'domready', function() {
        if (pano != null) {
            pano.unbind("position");
            pano.setVisible(false);
        }
        pano = new google.maps.StreetViewPanorama(document.getElementById("content"), {
          navigationControl: true
        });
        pano.bindTo("position", marker);
        pano.setVisible(true);
    });

    google.maps.event.addListener(infowindow, 'closeclick', function() {
        pano.unbind("position");
        pano.setVisible(false);
        pano = null;
    });
    
    google.maps.event.addListener(marker,'click', (function(marker,content,showInfoWindow){ 
        return function() {
            infowindow.setContent(content);
            infowindow.open(map,marker);
        };
    })(marker,content,infowindow)); 
}
});

【问题讨论】:

  • 请提供一个minimal reproducible example 来证明您的问题(包括示例数据),最好在问题本身中提供一个有效的StackSnippet
  • Hello geocodezip :) 我尽可能地净化了代码,我认为删除更多是没有意义的。在这种情况下,不可能制作一个工作示例,因为它是一个带有数据库的服务器端功能。我已经看过你的例子,我想知道 google.maps.MVCObject() 是否需要它才能工作。谢谢你的回复。
  • 我们如何在没有您的数据的情况下重现该问题?我可以弥补一些,但这需要时间,我现在没有,也许其他人有。

标签: google-maps google-street-view


【解决方案1】:

终于用你的例子找到了解决方案。谢谢。

$.ajax({
    url : 'category/subdi.php',
    async: true,
}).done(function(json){ 
    var data = JSON.parse(json);
    for(var i = 0; i < data.length; i++){
        
        var content = '<h6 class="text-success">'
        + data[i].subdi_name 
        + '</h6> Adresse : ' + data[i].subdi_place 
        + '<br/>Gestionnaire : ' 
        + data[i].subdi_gest;

        var icon_subdi = new google.maps.MarkerImage("img/map/subdi.svg");
        var marker = new google.maps.Marker({
            position: {lat: parseFloat(data[i].subdi_lat), lng: parseFloat(data[i].subdi_long)},
            icon: icon_subdi,
            title: data[i].subdi_name,
            animation: google.maps.Animation.DROP,
            map: map
        }); 
        marker.myHtml = content;

        var infoWindowContent = document.createElement("div");
        infoWindowContent.style.width = "600px";
        var htmlContent = document.createElement("div");
        infoWindowContent.appendChild(htmlContent);
        var streetview = document.createElement("div");
        streetview.setAttribute("id", "street");
        streetview.style.width = "100%";
        streetview.style.height = "300px";
        infoWindowContent.appendChild(streetview);

        var infowindow = new google.maps.InfoWindow({ content: infoWindowContent});
        infoWindows.push(infowindow);

        google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){ 
            return function() {
                openInfoWindow(marker);
            };
        })(marker,content,infowindow));

        function openInfoWindow(marker) {
            htmlContent.innerHTML = marker.myHtml;
            pin.set("position", marker.getPosition());
            infowindow.open(map, marker);
        }

        var panorama = null;
        var pin = new google.maps.MVCObject();

        google.maps.event.addListenerOnce(infowindow, "domready", function() {
            panorama = new google.maps.StreetViewPanorama(streetview, {
                navigationControl: false,
                enableCloseButton: false,
                addressControl: false,
                zoomControl: false,
                linksControl: false,
                panControl: false,
                visible: true
            });
            panorama.bindTo("position", pin);
        });

        subdiMarkers.push(marker);

    }
    subdiCluster = new MarkerClusterer(map,subdiMarkers, subdiClusterStyle);
    
}); 

【讨论】:

  • 有人知道如何使标记在街景全景图中可见吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多