【发布时间】:2016-03-16 10:26:49
【问题描述】:
我正在使用这个插件 cordova-plugin-googlemaps 虽然问题不受限制 我的结果数组,包括名称、地址和经纬度。 我用 for 循环将标记放在地图上。 点击标记打开信息窗口。
但我想要的是通过单击列表视图项目来打开特定的标记信息窗口。
我正在发布一些代码以获得微妙的想法。
for (; i < noOfData; ++i) {
(function(n) {
setTimeout(function() {
var position = new plugin.google.maps.LatLng(resultList[n].latitude, resultList[n].longitude);
markers.push(position);
$rootScope.map.addMarker({
'position': position,
'title': resultList[n].name,
'index': n,
'snippet': resultList[n].address,
"styles": {
'text-align': 'center',
'font-style': 'italic',
'color': 'red'
},
disableAutoPan: false
}, function(marker) {
$scope.listResults = resultList;
if ((+n + 1) == noOfData) {
var latLngBounds = new plugin.google.maps.LatLngBounds(markers);
console.log(hashCodeArrayOfMarkers.toString());
$rootScope.map.animateCamera({
'target': latLngBounds,
'zoom': 15,
'duration': 1000 // 1 seconds
});
}
marker.addEventListener(plugin.google.maps.event.MARKER_CLICK, function() {
var indexOfMarkerClicked = marker.get("index");
marker.showInfoWindow();
$scope.clickList(indexOfMarkerClicked);
marker.showInfoWindow();
marker.getPosition(function(latLng) {
$rootScope.map.animateCamera({
'target': latLng,
// 'zoom': 16,
'duration': 400
});
});
});
});
}, 0 + (0 * n));
})(i);
}
我想从项目单击列表中获得相同的结果。 我可以将相机移动到标记,因为我有 latLng,但我想打开 lat lng 上存在的相同标记的信息窗口。 请帮帮我。
【问题讨论】:
-
您可以简单地触发点击 .tigger() api.jquery.com/trigger 您必须将列表与标记同步
-
谢谢。我希望你不介意访问github.com/mapsplugin/cordova-plugin-googlemaps/wiki/Marker。他们暂时没有触发功能。而且我还有一系列标记。我从 addEventListener 打开特定标记的 info_window。有什么办法可以使用键值或类似的东西。如果你能帮忙就太好了。
-
列表和标记是从同一个数据集中生成的吗?
-
是的,它们是从同一个数据集生成的。 onMarkerClick 我得到了索引值。使用索引值,我在弹出窗口中显示来自同一数据集的详细信息
-
如果它们是从同一数据集生成的,则列表索引等于标记。所以只需点击 List index .index() .eq() 拿这个索引触发 onMarkerClick(indexFromList)
标签: javascript cordova google-maps