Seperate Marker For Each Location Type In Google Places Api
i have the following code to show school and mosque near to some location.
Solution 1:
In your createMarker function, you can refer to place.types
- an array of types. NB: some of the places will be of more than one type. You should check to see if that array contains either 'school' or 'mosque', and set the icon to use for that marker as appropriate.
base_Icon_school = "<?phpecho JURI::base();?>components/com_properties/includes/img/school.png";
base_Icon_mosque = "<?phpecho JURI::base();?>components/com_properties/includes/img/mosque.png";
shadow_Icon = "<?phpecho JURI::base();?>components/com_properties/includes/img/house-shadow.png";
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker;
var icon_to_use;
if (place.types.indexOf('school') != -1) {
icon_to_use = base_Icon_school;
} else if (place.types.indexOf('mosque') != -1) {
icon_to_use = base_Icon_mosque;
}
marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
shadow: shadow_Icon,
icon: icon_to_use
});
google.maps.event.addListener(marker, 'mouseover', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
See: https://developers.google.com/maps/documentation/javascript/reference#PlaceResult
Post a Comment for "Seperate Marker For Each Location Type In Google Places Api"