Auto Zoom When Marker is Placed

Easily set a new map zoom level when a marker is placed.

Instructions

  1. Install our free Custom Javascript for Gravity Forms plugin.
    Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
    
    1. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.

Code

Filename: gpaa-map-marker-placed-auto-zoom.js

/**
 * Gravity Perks // GP Address Autocomplete // Auto Zoom When Marker is Placed
 *
 * Easily set a new map zoom level when a marker is placed.
 *
 * https://gravitywiz.com/documentation/gravity-forms-address-autocomplete
 *
 * Instructions:
 *     1. Install our free Custom Javascript for Gravity Forms plugin.
 *        Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
 *     2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
 */

/**
 * Adjust this value to customize the zoom level when a marker is placed.
 * Smaller numbers are more zoomed out and larger numbers are more zoomed in.
 */
var zoomLevel = 20;

window.gform.addAction('gpaa_marker_set', function(args) {
	args.map.setZoom(zoomLevel);
})

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.