【发布时间】:2017-12-30 10:34:26
【问题描述】:
我有一组文章链接到谷歌地图上的标记。我正在使用 Laravel 5 和谷歌地图 API。当我点击一篇文章时,它的信息 div 会展开,谷歌地图信息窗口也会展开。
我想要做的是点击一个谷歌地图标记并展开文章信息 div。即我希望它能够双向工作。
文章是动态创建的。
这是我的谷歌地图代码的相关部分:
var barID = [
@foreach($articles as $article)
{{$article->id}},
@endforeach
];
for (i = 0; i < locations.length; i++) {
infoWindowContent[i] = getInfoWindowDetails(locations[i]);
var location = new google.maps.LatLng(locations[i][0], locations[i][1]);
var marker = new google.maps.Marker({
position: location,
map: map,
id: barID[i],
icon: 'images/happymarker.png'
});
var infoBubble = new InfoBubble({
map: map, etc..
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoBubble.setContent(infoWindowContent[i]);
infoBubble.open(map, marker);
map.panTo(marker.getPosition());
map.setZoom(17);
}
})(marker, i));
markers.push(marker);
}
// SHOW MORE INFO BUTTON TRIGGERS INFOWINDOW/MARKER
function myClick(id){
google.maps.event.trigger(markers[id], 'click');
}
这是我的尝试 - 但它不起作用。
marker.addListener('click', function(theID) {
$(".descriptionTextContainer" + theID).show();
});
标记/文章(地图容器外)。我已经为所有文章添加了一个 id,因此它将是 class="descriptionTextContainer 24" - 即所有不同的文本容器在它们的类中都有唯一的 id。
<article class="barContainer mix category-<?php echo $article->id; ?>" data-rating="<?php echo $article->rating; ?>" data-distance="<?php echo $article->distance; ?>">
$something = $articles->lists('id');
$artID = $article->id;
$key= $something->search($artID); ?>
// THIS IS THE PLACE WHERE I CLICK TO SHOW THE 'descriptionTextContainer'
<div class="resultsTitle showMoreDetails" onclick="myClick(<?php echo $key; ?>);">
<div class="barTitleContainer"><h2>{{$article->title}}</h2></div>
</div>
<div class="descriptionTextContainer <?php echo $key; ?>">
// THIS IS HIDDEN TILL THE MARKER OR THE 'ShowMoreDetails' is clicked
</div>
</article>
这里是the site,因为它正在使用 atm。
【问题讨论】:
标签: javascript google-maps google-maps-api-3 laravel-5