Support

Account

Home Forums General Issues Link to Google Map marker from outside of map Reply To: Link to Google Map marker from outside of map

  • I actually did that here: http://energycoalition.org/energy-architects-in-action/

    in the add_marker portion I updated it to this:

    /*
    	*  add_marker
    	*/
    	 
    	function add_marker( $marker, map ) {
    	 
    		// 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: '...'
    		});
    
    	 
    		// add to array
    		map.markers.push( marker );
    
    		
    	 
    		// if marker contains HTML, add it to an infoWindow
    		if( $marker.html() )
    		{
    			// create info window
    			
    	 
    
    			 liTag=$("body ul.utilities").find("[data-lat='" + $marker.attr('data-lat') + "']");
    			 // console.log(liTag);
    			// show info window when marker is clicked
    			$(liTag).click(function() {
    				infowindow.setContent($marker.html());
    				infowindow.open(map, marker);
    			});
    
    			google.maps.event.addListener(marker, 'click', function() {
    				infowindow.setContent($marker.html());
    				infowindow.open(map, marker);
    			});
    
    			// close info window when map is clicked
    		     google.maps.event.addListener(map, 'click', function(event) {
    		        if (infowindow) {
    		            infowindow.close(); }
    				}); 
    
    		}
    	 
    	}

    I use to separate loops, one to output the list items, and one for the map. In the list items I add the latitude to the LI itself