Google Maps v3 API and WordPress ACF: Multiple Custom Markers Google Maps v3 API and WordPress ACF: Multiple Custom Markers wordpress wordpress

Google Maps v3 API and WordPress ACF: Multiple Custom Markers


Charlotte, you could add a "data-marker" attribute to each of your marker objects as you build the markup, like this (green/grey wherever you need them)

<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; data-marker="green/grey" ?>">

And then in the javascript you can check the marker type using the data-marker you set in the code, like this

var grayCircle = {    //path: 'M -1,0 A 1,1 0 0 0 1,0 1,1 0 0 0 -1,0 z',    path: google.maps.SymbolPath.CIRCLE,    fillColor: '#888888',    fillOpacity: 1,    scale: 3,    strokeColor: "#888888",    strokeWeight: 3};var greenMarker = //create your marker here//Check your marker type, if it's green then set that otherwise leave it greyvar markerType = $marker.attr('data-marker')=="green"?greenMarker:greyCircle;var marker = new google.maps.Marker({    position: latlng,    //Set your marker using markerType here    icon: markerType,    map: map});