我想创建一个谷歌地图标记列表,其中填写InfoWindows关于这些特定位置的信息,并在InfoWindow内部提供有关该位置的维基百科文章的链接。我在此google.maps.event.addListener(place.marker, 'click', function() {}
点击函数中进行了 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);
}
}
答案 0 :(得分:0)
我认为你的实现可能会对错误做些什么。检查创建的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 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 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
});