Reply To: How to read and save map view (lat/lng/zoom)

Home Forums MapPress Support How to read and save map view (lat/lng/zoom) Reply To: How to read and save map view (lat/lng/zoom)

#15624
Chris
Keymaster

    Hi,

    This is really outside the scope of the plugin, so I can only offer some suggestions. But I think I can answer your questions:

    1. You can detect a map move using javascript. You’ll need the map’s name – the default is ‘mapp0’ for the first map on the page and ‘mapp1’, etc. for subsequent maps. Or, you can use the ‘name’ parameter in the shortcode. Then use this code to get a handle to the Google Map object:
    var map = mapp0.getMap();

    2. With the map handle you can register an event when the map bounds change (i.e. on a pan or zoom event). For example:

    
    jQuery(document).ready(function() {
    	var map = mapp0.getMap();
    	google.maps.event.addListenerOnce(map, "bounds_changed", function() {
    		// Your code here, for example:
    		var center = map.getCenter();
    		var zoom = map.getZoom();
    	});
    });
    

    If you save the new center/zoom as metadata, you can probably use PHP to output a mappress shortcode with saved center/zoom.

    For reference, the Google Maps API documentation is here:
    https://developers.google.com/maps/documentation/javascript/reference