Geocoder - initial zoom

Hi guys,

Using the sample_map_multi.php example with the geocoder plugin, the resulting map automatically zooms to display the results... which is great.  However, is there a way to identify the minimum "zoom"?  So when a search displays multiple locations - it zooms out to display all results.  However if only 1 result is displayed, the map is too focused.

I've tried adding "zoom: 13," to the mapOptions - but I think this is being overwritten by the "var bounds"?

Cheers,

Tim (toledoh.com.au)

By Toledoh - December 2, 2016

Hey Ross.

By default, /cmsb/plugins/geocoder/examples/sample_map_multi.php automatically zooms to fit all the found records.  

This is a great feature, and I'm using this example as a search results display.  ie. If I search all records, the whole of Australia shows as there are results all around Australia... if you narrow the search it just displays a few records and the map zooms in to show just that state etc.  However, when just 1 record is found - this zooms the display to fit just that 1 record... so it shows just that single property (not even the street).  I want the map to still stay zoomed out to show at least the suburb.

Does that explain things better?

Cheers,

Tim (toledoh.com.au)

By Dave - December 5, 2016

Hey Tim, 

Here's some steps I'd recommend to move forward.  

  1. See if you can figure out how to set the desired level of zoom on a test map that returns just 1 result.
  2. Then on the page that returns multiple results add some code to get a count of the results.  
  3. Then add a PHP if block so if there is just one result it adds the javascript code to set the desired zoom, and otherwise it adds the javascript code to set the zoom so it allows all the records to show.

Let me know if that works for you!

Dave Edis - Senior Developer
interactivetools.com