【发布时间】: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