Support

Account

Home Forums ACF PRO ACF PRO multiple google maps markers zoom level

Solved

ACF PRO multiple google maps markers zoom level

  • Hello!

    I am using standard code from documentation to display out multiple markers on google maps.
    My problem is that I’m unable to change zoom level of that map.
    With single marker map.setZoom(); works but not with multiple markers.

    I can’t wrap my head around it, what am I doing wrong ?

  • For me, I have done like this and it kinda worked for me.
    On Function center_map, if you are using more than 1 marker then on else section add

    map.setCenter( bounds.getCenter() );
    		map.setZoom( 4 );
    /* center_map */
    function center_map( map ) {
    	// vars
    	var bounds = new google.maps.LatLngBounds();
    	// loop through all markers and create bounds
    	$.each( map.markers, function( i, marker ){
    		var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
    		bounds.extend( latlng );
    	});
    	// only 1 marker?
    	if( map.markers.length == 1 )
    	{
    		// set center of map
    	    map.setCenter( bounds.getCenter() );
    	    map.setZoom( 4 );
    	}
    	else
    	{
    		// fit to bounds
    		//map.fitBounds( bounds );
    		map.setCenter( bounds.getCenter() );
    		map.setZoom( 4 );
    
    	}
    }
  • Yes! Thanks you debendra, just what i was looking for. I wonder why ACF team didn’t come up with this…

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘ACF PRO multiple google maps markers zoom level’ is closed to new replies.