Home › Forums › Feature Requests › Specify zoom in google map field › Reply To: Specify zoom in google map field
For a project i need to save the zoom of a google map field.
So i do this :
In core/fields/google-map.php
I added in create_field :
$field['value'] = wp_parse_args($field['value'], array(
'address' => '',
'lat' => '',
'lng' => '',
'zoom' => ''
));
and
$keys = array(
'data-id' => 'id',
'data-lat' => 'center_lat',
'data-lng' => 'center_lng',
'data-zoom' => 'zoom'
);
And in js/input.js
// value exists?
var lat = this.$el.find('.input-lat').val(),
lng = this.$el.find('.input-lng').val(),
zoom = parseInt(this.$el.find('.input-zoom').val());
if( zoom )
{
this.map.setZoom(zoom);
}
and
google.maps.event.addListener( this.map, 'zoom_changed', function( e ) {
// reference
var $el = this.$el;
var zoom = this.getZoom();
// update input
$el.find('.input-zoom').val( zoom ).trigger('change');
});
And it works.
Hope this help.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.