I've created a button inside my info window that needs to pan to the marker and then zoom in but I can't get it to work. Below is my Zoom function
function Zoom(){
google.maps.event.addListener(marker, 'click', function() {
map.panTo(marker.position);
map.setZoom(18);
});
and this the function that creates the marker and fills the info window with the html below.
function createMarker(latlng, name, woonplaats, prijs, perceelop, woonop, address) {
var html ="<a href="+address+">"+"<b>"+name+"</b></a> <br/>"
+ woonplaats +"</br>" + woonop + "/ " + perceelop + "</br>" + "€ " + prijs +
"</br><input id='zoombutton' type='button' onclick='Zoom()' value='Zoom in' />"
var marker = new google.maps.Marker({
map: map,
position: latlng
});
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
markers.push(marker);
}
If I remove the panTo function it does Zoom in, but it doesn't pan to the marker so it zooms in in a totally different place. I also tried to make the button invisible if the zoom level is 18 or higher but with no result.
Any help will be highly appreciated!
marker.position
is an undocumented parameter (if it exists). Usemarker.getPosition()
to get the marker's position.I get a javascript error with your code though:
Uncaught ReferenceError: marker is not defined
marker
in the button onclick functionworking fiddle
code snippet: