Support

Account

Home Forums Front-end Issues Google map location Reply To: Google map location

  • Here is my add_marker() function:

    function add_marker( $marker, map ) {
    	
    	var iconBase = '<?php echo get_bloginfo('template_directory')  ;?>/images/';
     
    	// var
    	var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
     
    	// create marker
    	var marker = new google.maps.Marker({
    		position	: latlng,
    		map			: map,
    		
    		icon: iconBase + $marker.attr('data-pin') + '-pin.png'
    	});
     
    	// add to array
    	map.markers.push( marker );
     
    	// if marker contains HTML, add it to an infoWindow
    	if( $marker.html() )
    	{
    		// create info window
    		var infowindow = new google.maps.InfoWindow({
    			content		: $marker.html()
    		});
     
    		// show info window when marker is clicked
    		google.maps.event.addListener(marker, 'click', function() {
     
    			infowindow.open( map, marker );
     
    		});
    	}
     
    }

    “data-pin” comes from a data element generated by WordPress category.

    Hope that helps.

    neil