Reputation: 117
I'm using the google maps in one of my projects but I don't want to have zooming affect in the map so I disabled it via
zoomControl: false,
however, this only works for desktops and laptops as they dont support multi touch.
when i view my map in a device that supports multi touch like tablets or smart phones, I can zoom in using pinch and zoom on the device.
I did try map2.getUiSettings().setZoomControlsEnabled(false);
which has no affect on it and I still can pinch and zoom!
I also tried map.getUiSettings().setZoomControlsEnabled(false);
to see if that makes any different but it doesn't!
could someone please advise on this issue?
This is my full code:
<script>
function showCurrentLocation(position) {
var latitude = <?php echo $curLat; ?>;
var longitude = <?php echo $curLon; ?>;
var coords2 = new google.maps.LatLng(latitude, longitude);
var mapOptions2 = {
zoom: 10,
center: coords2,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
zoomControl: false,
scrollwheel: false,
navigationControl: false,
mapTypeControl: false,
scaleControl: false,
draggable: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
//create the map, and place it in the HTML map div
map2 = new google.maps.Map(
document.getElementById("mapPlaceholder"), mapOptions2);
//place the initial marker
var marker2 = new google.maps.Marker({
position: coords2,
map: map2,
title2: "Current location!"
});
}
google.maps.event.addDomListener(window,'load',showCurrentLocation);
map2.getUiSettings().setZoomControlsEnabled(false);
</script>
any help would be appreciated.
Upvotes: 1
Views: 3653
Reputation: 11
Add this code to your mapOptions:
minZoom: 10,
maxZoom: 10
Basically, set minZoom and maxZoom to the same value to disable zoom on your map.
Upvotes: 1
Reputation: 376
You might want to try:
var tblock = function (e) {
if (e.touches.length > 1) {
e.preventDefault()
}
return false;
}
document.body.addEventListener("touchmove", tblock, true);
Related:
Disabling pinch-zoom on google maps [Desktop]
Google Maps API v3 Disable Pinch to Zoom on iPad Safari
Edit (working example on Android 4.4.2):
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html, body, #mapPlaceholder {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script type="text/javascript">
var map2;
function initialize() {
var coords2 = new google.maps.LatLng(38.8, -77);
var mapOptions2 = {
zoom: 10,
center: coords2,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
zoomControl: false,
scrollwheel: false,
navigationControl: false,
mapTypeControl: false,
scaleControl: false,
draggable: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
//create the map, and place it in the HTML map div
map2 = new google.maps.Map(document.getElementById("mapPlaceholder"), mapOptions2);
//place the initial marker
var marker2 = new google.maps.Marker({
position: coords2,
map: map2,
title: "Current location!"
});
var tblock = function (e) {
if (e.touches.length > 1) {
e.preventDefault()
}
return false;
}
document.body.addEventListener("touchmove", tblock, true);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="mapPlaceholder"></div>
</body>
</html>
Upvotes: 3