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.
Question
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.
Solution
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.