Support

Account

Home Forums General Issues Google Maps – Passing Variables Reply To: Google Maps – Passing Variables

  • Solved my issue.

    I added data attributes to the marker HTML:
    <div class="marker" data-type="<?php echo $map_display_setting; ?>" data-zoom="<?php echo $map_zoom_level; ?>" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>

    And then set global variables:

    		var marker = $('.marker');
    			var zoomLevel = marker.data('zoom');
    			var mapType   = marker.data('type');

    And then altered the code below:

    		// vars
    		var args = {
    			zoom		  : zoomLevel,
    			center		: new google.maps.LatLng(0, 0),
    			mapTypeId	: google.maps.MapTypeId[mapType]
    		};

    and

    		// only 1 marker?
    		if( map.markers.length == 1 )
    		{
    			// set center of map
    		    map.setCenter( bounds.getCenter() );
    		    map.setZoom( zoomLevel );
    		}