문제

I have just updated my code from v2 to v3. Every thing is working but the function map.fitBounds(); Here is my sample code

   var geocoder = new google.maps.Geocoder();

   geocoder.geocode( { 'address': 'your address'}, >function(results, status) { 
       if (status == google.maps.GeocoderStatus.OK) { 

           var newPoint = new google.maps.LatLng(results[0].geometry.location.lat(), >results[0].geometry.location.lng());
           markerBounds.extend(newPoint); 

           var marker = new google.maps.Marker({ 
               map: map,  
               position: results[0].geometry.location 
           }); 
 
       } else { 
           alert('Geocode was not successful for the following reason: ' + status); 
       } 
   }); 

   map.fitBounds(markerBounds);

}

I have found that this code looks fine but here fitBounds() will not work. The required change is mention in the answer below.

도움이 되었습니까?

해결책

In this case we have to write code like this

markerBounds.extend(newPoint);
map.fitBounds(markerBounds); // here in function rather in the end

This worked for me hopefully will work for you as well.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top