Geocoder - initial zoom

By Toledoh - November 23, 2016

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 ross - November 28, 2016

Hi Tim

Thanks for posting.

To start, I want to make sure I understand what you are aiming for.  

What I am getting is you want to dynamically set the zoom of your map based on where all the pins are.  Basically, set the zoom automatically to display all pins on the map. 

If that's the case, I think the solution is going to be something along the lines of one of these ideas:

http://stackoverflow.com/questions/19304574/center-set-zoom-of-map-to-cover-all-visible-markers

http://stackoverflow.com/questions/2362337/how-to-set-the-google-map-zoom-level-to-show-all-the-markers

Let me know if I am on the right track with my idea and these links. We can get into more detail if you like from there.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

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