Google 地图街景信息 wIndows 在地图上打开

Google Maps StreetView InfowIndows opening on map

当我将标记和信息窗口添加到我的 Google 地图应用程序时,标记会正确添加到地图和默认的 StreetView 全景图中。

我还通过调用我的 bindInfoWindow 函数将 InfoWindows 添加到标记的两个副本中,一次使用地图作为参数,一次使用 StreetView 全景图作为参数。

直到几周前,它还运行良好。

现在,出于某种原因,两个信息窗口都显示在地图上,并附在地图标记上。

我创建了一个simple fiddle (based on this public fiddle) which shows the problem here

基本上我以正常方式创建标记和信息窗口:

    var myMarker = new google.maps.Marker({
            map: map,
                position: new google.maps.LatLng(-34.397, 150.644),
                title: "My Marker",
                draggable:true,
            });

然后我使用我的 bindInfoWindow 函数

function bindInfoWindow(marker, mapOrStreetView, whichInfoWindow, html, openWindow,markerId) {
    openWindow = ((typeof openWindow === 'undefined')?false:openWindow);
    markerId = ((typeof markerId === 'undefined')?'':markerId);
    google.maps.event.addListener(marker, 'click', function() {
        whichInfoWindow.setContent(html);
        whichInfoWindow.open(mapOrStreetView, marker);
    });
    if ( openWindow === true ) {
        whichInfoWindow.setContent(html);
        whichInfoWindow.open(mapOrStreetView, marker);
    }
}

为标记创建 onClick 操作,并在需要时自动打开信息窗口。

            var myMarkerInfoWindow = new google.maps.InfoWindow;
            bindInfoWindow(myMarker, map, myMarkerInfoWindow, "<h1>My Map Info Window Text<br /> <br /></h1>", true);
            var myMarkerStreetViewInfoWindow = new google.maps.InfoWindow;
            bindInfoWindow(myMarker, defaultStreetViewPanorama, myMarkerStreetViewInfoWindow, "<h1>My StreetView Info Window Text</h1>", true);

直到大约一两个星期前,这一直运行良好,但突然之间,InfoWindows 都出现在地图上,而不是一个出现在地图上,一个出现在默认的 StreetView 上。

the fiddle中,您可以清楚地看到街景信息窗口已在主地图信息窗口的顶部打开,尽管已指定在街景视图上打开。

请注意,map 是我的地图对象,defaultStreetViewPanorama 是使用

检索到的 StreetView Panormama 对象
var defaultStreetViewPanorama = map.getStreetView();

就在创建地图对象之后和设置 StreetView 选项之前。请注意,StreetView 选项 的正确设置,因此 map.getStreetView() 似乎返回了正确的对象。

Google 在 v3.25 中破坏了此功能。

v3.24 是最后一个正常运行的版本。

v3.24 已停用且不再可用 - 在此期间似乎没有任何简单的解决方法。

此问题已在 https://code.google.com/p/gmaps-api-issues/issues/detail?id=9925 的 bug-tracker 上用 Google 记录,并已被接受,但在撰写本文时尚未解决。

我会更新这个答案if/when有任何进展。

这里有一个重复的问题:

当您尝试在 Google 地图和该地图的 StreetViewPanorama 中使用相同的标记实例并希望在两者中显示信息窗口时,就会出现此问题。

如果您在 StreetViewPanorama 对象的信息窗口的打开方法中指定标记,则应该在 StreetView 中显示的信息窗口会显示在地图中。 这是不正确的行为。

我的解决方案如下:

我创建了一个 codepen 来显示此修复: https://codepen.io/moutono/pen/KjZpZB

这里的问题似乎是,当您像这样打开信息窗口时,附加到标记的地图对象替换了信息窗口中的地图对象:

streetViewInfowindow.open(panorama, marker); //Won't work because the panorama object is replaced by the map object attached to the marker.

因此,如果您想在街景视图和地图中的同一标记上显示信息窗口,则必须这样做:

mapInfowindow.setPosition(position);
mapInfowindow.open(map);
streetViewInfowindow.setPosition(position);
streetViewInfowindow.open(panorama); //This works because panorama object is not replaced by map object from marker.

Link 到 Google Issue Tracker