Disable Google Map Zoom

By nmsinc - January 21, 2014

Hello,

I'm trying to disable Google Map Zoom below with no luck - any suggestions? - Thanks NMSINC

function _geocoder_addMarker(latitude, longitude, recordNum, detailLink) {
    var mapOptions = {
    zoom: 4,
    scrollwheel: false,
    zoomControl: false    
    }
    var latLng       = new google.maps.LatLng(latitude, longitude);
    var infowindowEl = document.getElementById('marker_infowindow_' + recordNum);
    var image        = "<?php echo $pointerUrl3; ?>man.png";
    var marker       = new google.maps.Marker({ map: map, position: latLng, icon:image });
    google.maps.event.addListener(marker, 'click', function() {
    });
    bounds.extend(latLng);
  }

nmsinc

By gregThomas - January 23, 2014

Hi Nmsinc,

I think the problem is that you're applying these options to the map marker, as opposed to the map. I did some local testing and was able to disable zooming on the sample_map_multi.php example map that comes with geocoder plugin using this code:

<!-- STEP1: Map with multiple addresses: Put this in the <head> of your page, rename $myRecords if needed -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
  var mapCanvasId = 'map_canvas';
  var mapOptions  = { 
    mapTypeId:   google.maps.MapTypeId.ROADMAP,
    scrollwheel: false,
    zoomControl: false     
  };
  var map         = new google.maps.Map(document.getElementById(mapCanvasId), mapOptions);
  var bounds      = new google.maps.LatLngBounds();
  var infowindow  = new google.maps.InfoWindow();

<?php
foreach ($myRecords as $record) {
  if (!$record['latitude'] || !$record['longitude']) { continue; }
  $jsFunctionArgs = "{$record['latitude']}, {$record['longitude']}, {$record['num']}, '" .escapeJs($record['_link']). "'";
  print "  _geocoder_addMarker($jsFunctionArgs);\n";
}
?>

  //
  function _geocoder_addMarker(latitude, longitude, recordNum, detailLink) {
    var latLng       = new google.maps.LatLng(latitude, longitude);
    var infowindowEl = document.getElementById('marker_infowindow_' + recordNum);
    var marker       = new google.maps.Marker({ map: map, position: latLng });
    google.maps.event.addListener(marker, 'click', function() {
      if (infowindowEl) {
        infowindow.setContent(infowindowEl.innerHTML);
        infowindow.open(map, marker);
      }
      else {
        window.location = detailLink;
      }
    });
    bounds.extend(latLng);
  }

  //
  map.fitBounds(bounds);
}

</script>

The changes I've made I've highlighted in green. So instead of passing the mapOptions variable into the marker, they're passed into the map initialize function.

Let me know if you have any questions!

Cheers!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gregThomas - January 23, 2014

Hi nmsinc,

I can't see anything wrong with your code, do you have a link to the page so that I can take a look? Are you getting any errors? Or is it just that the scroll bar still appears on the page?

Thanks,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gregThomas - January 23, 2014

Hi nmsinc,

It's working correctly for me:

http://awesomescreenshot.com/0af28zjk1f

I was unable to zoom in or out either. Have you tried doing full refresh of the page (ctrl+F5)?

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By nmsinc - January 23, 2014

I did a the f-5 refresh and the scroll has been locked out, however, when I double click inside the map, it still zooms in!

nmsinc

By Toledoh - January 23, 2014

Just a thought.

Have a play with http://googlemapbuilder.mynameisdonald.com/ then generate the code to see what it produces.

There is an option for Zoom Control, as well as Double Click to Zoom and Mouse Wheel to Zoom. 

Cheers,

Tim (toledoh.com.au)

By nmsinc - January 23, 2014

Duh, I should have thought of that - that worked --- SORRY Big Time!

nmsinc