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.valenc...@[mail_at]@[gmail.com"
<[email protected]> 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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.