简体   繁体   English

为什么我不能单击我的标记来在Google Maps中拉起信息窗口?

[英]Why can't I click my markers to pull up infowindow in Google Maps anymore?

I have a web application using the Google Maps API and has been working fine. 我有一个使用Google Maps API的网络应用程序,并且运行良好。 The page still works but one day randomly I found out that the markers can no longer be clicked but has worked for me previously for a long time. 该页面仍然有效,但是有一天我随机发现标记不能再被单击,但是以前已经为我工作了很长时间。 I have not made any change to the code prior to this happening. 在此之前,我没有对代码进行任何更改。

Below is my code for the infowindow section: 下面是我的信息窗口部分的代码:

var infoWindow = new google.maps.InfoWindow();
    var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);

    for (i = 0; i < markers.length; i++) {
        var data = markers[i]
        var myLatlng = new google.maps.LatLng(data.lat, data.lng);
        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title: "Permit#" + " " + data.permit,
            icon: 'GoogleMapsMarkers/' + data.icon + '.png'

        });
        (function (marker, data) {
            google.map.event.addListener(marker, "click", function (e) {
                infoWindow.setContent('<b>' + data.loc + " " + data.type + '</b>' + '<br/><a target=_blank href="ViewPermit.aspx?PermNum=' + data.permit + '">' + 'Open Permit #' + " " + data.permit + '</a>');
                infoWindow.open(map, marker);
            });
        })(marker, data);
    }

I am using the script below for the api: 我将以下脚本用于api:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&amp;key=My_Key"></script>

I tried this and still same issue: 我尝试了这个并且还是同样的问题:

<script async defer
  src="https://maps.googleapis.com/maps/api/js?key=My_Key&callback=initMap">

Has something changed that I am not aware of? 我不知道有什么变化吗?

First of all, you should not share any API keys, passwords, any sensible data information. 首先,您不应共享任何API密钥,密码和任何明智的数据信息。 Try to use placeholders eg (API key), [API Key]. 尝试使用占位符,例如(API密钥),[API密钥]。

Have you tried to follow Google's official documentation: https://developers.google.com/maps/documentation/javascript/infowindows 您是否尝试过遵循Google的官方文档: https : //developers.google.com/maps/documentation/javascript/infowindows

Hope this will help you in your quest. 希望这对您的追求有所帮助。

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

相关问题 Google Maps API:为什么不能使用相对图标路径设置标记的图标? - Google maps API: Why can't I set the icon of my markers by using relative icon paths? 为什么我看不到谷歌地图上的任何标记有反应? - Why can't I see any markers on google maps react? 为什么我的 Javascript 代码不能访问 google.maps.InfoWindow 中的 div? - Why can't my Javascript code access a div inside a google.maps.InfoWindow? 在谷歌地图上显示 5 个标记的信息窗口,信息窗口是一个图表 - Display an InfoWindow for 5 markers on Google Maps, the Infowindow is a chart 如何在Google Maps标记信息窗口中为标记数组添加数组键数据项? - How can I add the array key data item in google maps marker infowindow for an array of markers? 为什么单击按钮后我的Google地图无法更新lat / lng? - Why Can't I get my google maps to update lat/lng on button click? 为什么我的Google地图标记没有加载? - Why don't my Google Maps Markers load? Google地图:无法显示InfoWindow - Google Maps: Can't get InfoWindow to display 信息窗口谷歌地图错误:无法访问词法声明“信息窗口” - infowindow google maps error: can't access lexical declaration 'infowindow' Google Maps API:删除您不再拥有的标记? - Google Maps API: Removing markers you don't have anymore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM