javascript - How to overwrite Google Map initialized opts with fitBounds(); -


i've been searching way overwrite google map's center latlng , zoom using fitbounds() method. can see have array of latlng coordinates fit within map @ correct zoom.

annoyingly, map ever takes latlng coordinates of center attribute when map initialized. please help, can't see i'm doing wrong. thanks

    function initialize() {     var centrelatlng = new google.maps.latlng(52.474, -1.868);      var myoptions = {         zoom:11,         center: centrelatlng,         maptypeid: google.maps.maptypeid.roadmap     };      var map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions);      var image = 'http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png';      var hotels = [         ['ibis birmingham airport', 52.452656, -1.730548, 4],         ['etap birmingham airport', 52.452527, -1.731644, 3],         ['ibis birmingham city centre', 52.475162, -1.897208, 2]     ];      var latlngs = [];     var hotel;     (var = 0; < hotels.length; i++) {         hotel = hotels [i];         var mylatlng = new google.maps.latlng(hotel[1], hotel[2]);         latlngs[i] = mylatlng;         var marker = new google.maps.marker({             position: mylatlng,             map: map,             icon: image,             title: hotel[0],             zindex: hotel[3]         });     }      var latlngbounds = new google.maps.latlngbounds();     latlngs.each(function(n){         latlngbounds.extend(n);     });     map.setcenter(latlngbounds.getcenter());     map.fitbounds(latlngbounds);   }; 

please note must scroll down code viewer see code.

don't set center in myoptions, , remove map.setcenter(latlngbounds.getcenter()); , should go.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -