It works like a charm. I searched for fitBounds issue for 1 day and could not find out why the map did not auto zoom and auto center until I saw your post. Thanks so much.
On Tuesday, February 16, 2010 10:16:28 AM UTC-6, pv.valencia]@[mail_at]@[gmail.com wrote: > > I solved the problem. Just adding map.fitBounds(bounds); > > after: > var marker = new google.maps.Marker({ > map: map, > position: results[0].geometry.location > }); > HERE > > So now the problem its solved. > > On 16 feb, 16:15, "pv.valencia]@[mail_at]@[gmail.com" > <pv.valen...@gmail.com> wrote: > > Hello, first, I paste my code including some comments: > > > > $(document).ready(function() { > > var geocoder; > > var map; > > var bounds = new google.maps.LatLngBounds(); > > > > // This function picks up an string and locates it into the map. > > function codeAddress(address) { > > if (geocoder) { > > geocoder.geocode( { 'address': address}, function(results, > > status) { > > if (status == google.maps.GeocoderStatus.OK) { > > map.setCenter(results[0].geometry.location); > > var marker = new google.maps.Marker({ > > map: map, > > position: results[0].geometry.location > > }); > > // here i want to extend the bounds AND HERE IS THE PROBLEM > > bounds.extend(results[0].geometry.location); > > } else { > > alert("Geocode was not successful for the following reason: > > " + status); > > } > > }); > > } > > } > > > > // Here i init the map > > geocoder = new google.maps.Geocoder(); > > var myOptions = { > > zoom: 8, > > mapTypeId: google.maps.MapTypeId.ROADMAP > > } > > map = new google.maps.Map(document.getElementById("mapa_google"), > > myOptions); > > > > codeAddress("ADDRESS_HERE"); > > alert(bounds); > > map.setCenter(bounds.getCenter()); > > map.setZoom(map.fitBounds(bounds)-1); > > > > }); > > > > Well, the problem is, the bounds where not extended. I get allways the > > same value. If I do an alert instead > > bounds.extend(results[0].geometry.location); I get the real value. > > > > I would like to get the bounds to make a zoom. I dont know how to > > extract this values outside the functions. Please help, I cant find > > any example about this. Thank you! > > -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-maps-js-api-v3+unsubscr...@googlegroups.com. To post to this group, send email to google-maps-js-api-v3@googlegroups.com. Visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en. For more options, visit https://groups.google.com/groups/opt_out.