我正在使用AJAX方法从web服务中检索标记,我想使用标记属性标题在地图上搜索它们。有可能吗?
这是我返回标记的函数:
function displayLocation(location) {
var content = '<strong>' + location.name + '</strong>';
var position = new google.maps.LatLng(parseFloat(location.coordinate[0]), parseFloat(location.coordinate[1]));
var marker = new google.maps.Marker({
map: map,
position: position,
title: location.name,
url: 'https://www.google.com.br/#q=' + location.name,
icon: 'img/restaurant_pin.png'
});
var label = new Label({
map: map
});
label.bindTo('position', marker);
label.bindTo('text', marker, 'title');
label.bindTo('visible', marker);
label.bindTo('clickable', marker);
label.bindTo('zIndex', marker);
google.maps.event.addListener(marker, 'click', function() {
window.location.href = marker.url;
});
}
假设markers
是您的标记数组,yourSearchPhrase
是您要搜索的内容:
for (var i=0; i<markers.length; i++) {
if (markers[i].title == yourSearchPhrase) {
// this marker's title equals your search phrase
}
}