Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDanny Luna
5,899 PointsEnable pinch zoom on google map for mobile device
How do i enable pinch zoom on iOS device. Everything works fine, i just need for users to be able to pinch zoom on the map only:
heres what i have:
HTML:
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, , user-scalable=yes">
<div id="map-canvas"></div>`
CSS:
#map-canvas {
margin: 1em auto;
width: 90%;
height: 9em;
}
JS:
//Google Map API
function initialize() {
var mapCanvas = document.getElementById('map-canvas');
var map = new google.maps.Map(mapCanvas);
var isDraggable = $(document).width() > 480 ? true : false; // If document (your website) is wider than 480px, isDraggable = true, else isDraggable = false
var myLatlng = new google.maps.LatLng(26.754051, -80.920592);
var mapOptions = {
center: myLatlng,
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
draggable: isDraggable,
scrollwheel: false, // Prevent users to start zooming the map when scrolling down the page
//... options options options
panControl: true,
scaleControl: true
}
var map = new google.maps.Map(mapCanvas, mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!'
});
}
google.maps.event.addDomListener(window, 'load', initialize);`