You redeclared "var map" inside initialize. Remove the "var" identifier inside your initialize function and it should work.
-- Sent from my Palm Pre On Mar 1, 2010 11:33 AM, AL <[email protected]> wrote: Hi, I'm a complete beginner to maps API and so far have struggled to fire an event triggered by a button on a page. I've checked the Google Code pages and examples but no luck... I simply wanted to set the map to center when user clicks a button. How do I do that? Here's my code (map.js): var map; function initialize() { var ZielonyJar = new google.maps.LatLng(49.80005, 19.0197); var myOptions = { zoom: 12, center: ZielonyJar, navigationControl: true, navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}, mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var image = '../images/house_icon.png'; var myMarker = new google.maps.Marker({ position: ZielonyJar, map: map, icon: image }); } centrujMape = function() { map.setCenter(ZielonyJar); } HTML: <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <script type="text/javascript" src="http://maps.google.com/maps/api/js? sensor=false&language=pl"></script> <script type="text/javascript" src="../include/map.js"></script> <div id="map_canvas" style="width: 600px; height: 400px; border: #fff 5px solid"></div> <input type="button" value="centruj" onclick="centrujMape()" /> I will appreciate your help on this matter. Thanks! -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en. -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
