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