Support

Account

Home Forums Backend Issues (wp-admin) How to get the lat/long values from the center input field in the GM field

Solved

How to get the lat/long values from the center input field in the GM field

  • Hi there. I’ve built a modified version of the google maps example from here: http://www.advancedcustomfields.com/resources/field-types/google-map/

    All is working fine except one tiny bit. If i display no markers the map is centered somewhere in the ocean around Howland Island 😉 instead using the default lat/long value from the google maps field. Per default it is Melbourne but i’ve entered my own lat long values.

    But is there a way to get those values from the advanced custom field to the js? So far i was only able to hardcode my values by adding if (map.markers.length == 0 ):

    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 == 0 ) {
          map.setCenter(new google.maps.LatLng(49.45203,11.07675));
          map.setZoom( 12 );
    	}
    	else if( map.markers.length == 1 )
    	{
    		// set center of map
    	    map.setCenter( bounds.getCenter() );
    	    map.setZoom( 16 );
    	}
    	else
    	{
    		// fit to bounds
    		map.fitBounds( bounds );
    	}
    }

    But i would prefer if the js would pull the given lat/lng values. Has anyone accomplished that yet? Best regards Ralf

  • @elliot also not working in acf 5.0 :/

  • hmmm seems that was a bug. I tried again few minutes again. The js part of the code hasn’t changed but it is working now. 😉 odd. but glad it is working now 🙂 best regards Ralf

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

The topic ‘How to get the lat/long values from the center input field in the GM field’ is closed to new replies.