I'm retrieving markers from web service using an AJAX method and I'd like to search them on the map using the marker property title. Is it possible?
This is my function thats returns the markers:
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;
});
}
Assume that markers
is your array of markers and yourSearchPhrase
is what you are searching for:
for (var i=0; i<markers.length; i++) {
if (markers[i].title == yourSearchPhrase) {
// this marker's title equals your search phrase
}
}