【问题标题】:How do you create a link in a Google Maps InfoWindow?如何在 Google Maps InfoWindow 中创建链接?
【发布时间】:2016-10-31 04:30:23
【问题描述】:

序言

我想创建一个 google 地图标记列表,这些标记会在 InfoWindow 中填充有关这些特定位置的信息,并在 InfoWindow 中创建一个指向有关该位置的 Wikipedia 文章的链接。我在这个google.maps.event.addListener(place.marker, 'click', function() {} click 函数中进行了 Ajax 调用,这个函数在一个 self.allPlaces().forEach(function(place) {} 函数中,它只是遍历我的所有位置。

问题

该链接填充在 InfoWindows 中,只有在您右键单击并在新选项卡中打开时才会打开,而我希望它只需单击左键即可打开。

function ajax() {
            return $.ajax({
                type: 'GET',
                url: wikiURL,
                dataType: "jsonp",
                prop: 'pageimages'
            });
        }

        ajax().done(function(response) {
            clearTimeout(self.apiTimeout);
            var articleList = response[1];
            console.log(response);
            if (articleList.length > 0) {
                for (var i = 0; i < articleList.length; i++) {
                    var url = response[3]; // response[3] gives back the wiki URL
                    content = '<div class="infoWindow"><strong>' + place.title + '</strong><br>' +
                                '<p>' + place.formatted_address + '</p>' +
                                '<p>' + response[2] + '</p>' + // response[2] for more modern response
                                '<a href="' + url + '" target="_blank">' +
                                "View full Wikipedia article" + '</a>' +
                    '</div>';
                    infoWindow.setContent(content);
                }
            }

【问题讨论】:

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


    【解决方案1】:

    我认为您的实现可能会对错误有所帮助。检查创建的content 变量是否类似于代码示例contentString 变量

    尝试并按照link 中的示例代码进行操作。

    代码示例:

    var contentString = '<div id="content">'+
    '<div id="siteNotice">'+
    '</div>'+
    '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
    '<div id="bodyContent">'+
    '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
    'sandstone rock formation in the southern part of the '+
    'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
    'south west of the nearest large town, Alice Springs; 450&#160;km '+
    '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+
    'features of the Uluru - Kata Tjuta National Park. Uluru is '+
    'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
    'Aboriginal people of the area. It has many springs, waterholes, '+
    'rock caves and ancient paintings. Uluru is listed as a World '+
    'Heritage Site.</p>'+
    '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
    'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
    '(last visited June 22, 2009).</p>'+
    '</div>'+
    '</div>';
    var infowindow = new google.maps.InfoWindow({
    content: contentString
    });
    

    【讨论】:

      猜你喜欢
      • 2016-07-12
      • 1970-01-01
      • 2017-09-20
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 2023-03-16
      • 2012-03-10
      • 2011-02-11
      相关资源
      最近更新 更多