Google Maps API V3 fitbounds() zooms out but never in

前端 未结 12 2425
感动是毒
感动是毒 2020-12-19 03:44

I\'ve created a quite complex store locator of sorts. The user enters their zip and a table returns results with corresponding markers on a map. They can page through result

12条回答
  •  情深已故
    2020-12-19 03:46

    Hmm, interesting.. I use PHP to loop through all (to be) marker coordinates and calculate the values of southWest and northEast; the coords of origin are halfway between the two. If all marker coordinates are very close to each other, the zoom factor set by fitBounds is much higher (zoomed in) than the 15 used at map creation. That's why I have added that last row..

    var map;
    
    function mapInit() {
      var origin = new google.maps.LatLng(59.33344615, 18.0678188);
      var options = {
        zoom: 15,
        center: origin,
        mapTypeControlOptions: {
          mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID]
        },
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
    
      map = new google.maps.Map(document.getElementById("googlemap"), options);
    
      var southWest = new google.maps.LatLng(59.3308415, 18.0643054);
      var northEast = new google.maps.LatLng(59.3360508, 18.0713322);
      var bounds = new google.maps.LatLngBounds(southWest, northEast);
      map.fitBounds(bounds);
    
      google.maps.event.addListenerOnce(map, "idle", function() {
        if (map.getZoom() > 16) map.setZoom(16);
      });
    

    So, either Google has reprogrammed the function since you posted the question or.. I need more information about your code.

提交回复
热议问题