The code gets mangled by the groups' software. So it's no good idea to
post larger code pieces here.

Try to put fitBounds() just before the end of your initialize()
function and see if that suits your needs. If not it should be
possible to change the order of execution or to use an event listener.

If you have further problems, please post a link.



On Jul 10, 12:26 pm, Lennart K <[email protected]> wrote:
> OK, I think I've mananged two of your three steps:
> Step 1: I have put 'var bounds' at the start of the initialize
> function.
> Step 2: I have put the 'bounds.extend(points);' in the 'for (var i =
> 0; i < markers.length; i++)' loop.
>
> But I can't figure out where to put 'map.fitBounds(bounds);'
> The whole function initialize() looks like this:
> function initialize()
> {
>  var bounds = new google.maps.LatLngBounds(); //Makes an empty bounds
> object
>  var latlng = new google.maps.LatLng(48.130000, 25.570000);
>  var myOptions = {
>       zoom: 4,
>       center: latlng,
>       mapTypeId: google.maps.MapTypeId.HYBRID
>     };
>  var map = new google.maps.Map(document.getElementById("map_canvas"),
> myOptions);
>  var infoWindow = new google.maps.InfoWindow;
>
> // Change this depending on the name of your PHP file
>  downloadUrl("min_genxml3.php?art=<?php echo $afart.'&dist='.
> $min_dist.'&tid='.$max_time;?>", function(data)
>  {
>   var xml = parseXml(data);
>   var markers = xml.documentElement.getElementsByTagName("marker");
>   for (var i = 0; i < markers.length; i++)
>   {
>    var icon = 'http://labs.google.com/ridefinder/images/
> mm_20_red.png';
>    var point = new
> google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),
>
> parseFloat(markers[i].getAttribute("lng")));
>    var mdat = 'Markt: '+markers[i].getAttribute("mdat");
>    var fdat = 'Funnen: '+markers[i].getAttribute("fdat");
>    var dist = 'Distans: '+markers[i].getAttribute("dist")+' km.';
>    var riktn = 'Riktning: '+markers[i].getAttribute("riktn")+'
> grader.';
>    var dgr = 'Tid: '+markers[i].getAttribute("dgr")+' dagar.';
>    var html = 'Märkt: '+markers[i].getAttribute("mdat")+'<br>Funnen:
> '+markers[i].getAttribute("fdat")+'<br>Förfluten tid:
> '+markers[i].getAttribute("dgr")+' dagar.';
>    var marker = new google.maps.Marker
>    (
>    {
>     position: point,
>         map: map,
>         title: dist+' '+riktn,
>     icon: icon
>    }
>    );
>    bindInfoWindow(marker, map, infoWindow, html);
>    // Feed your bounds object with your points
>    bounds.extend(points);
>   }
>  }
>  );
>
> }
>
> Could you please tell me where to put 'map.fitBounds(bounds);' among
> all these curly and non-curly brackets?
> Thank you
> Lennart
>
> On 10 Juli, 09:22, Pil <[email protected]> wrote:
>
> > This would be the basic approach
>
> > // Make a bounds object
> > var bounds = new google.maps.LatLngBounds();
>
> > // Feed your bounds object with your points
> > bounds.extend(points);
>
> > // Call fitBounds() so that the map viewport fits the bounds
> > map.fitBounds(bounds);
>
> > On Jul 10, 12:52 am, Lennart K <[email protected]> wrote:
>
> > > Hello,
> > > Still working with my maps of recovered ringed birds I really got
> > > stuck with the construction of dynamic maps, adjusted to the locations
> > > of recoveries for different bird species - some are all i Europe, some
> > > extend to southern Africa. I want the bounds and the zoom level of the
> > > maps to be set according to these variations.
> > > Data are taken from a mysql-db and thus it's easy to get the
> > > coordinates for the bounds of the maps for a selected species by
> > > selecting the max/min latitudes and logitudes respectively. You can
> > > then get the SW and NE corners and by adding/subtracting one or two
> > > degrees you may avoid to get the markers in the very corners.
> > > Example:
> > > SW=43.883331, -3.116667;
> > > NE=61.483334, 24.383333;
> > > This should be put into a new google.maps.LatLngBounds(), shouldn't
> > > it?
> > > Please show me the exact syntax for this.
> > > And then you should use setCenter(something) to get the center of the
> > > map, shouldn't you?
> > > Then the latlng of the required center position would be fullfilled.
>
> > > Now I want to bring this into the initialization of the map.
>
> > > The static map initialization is:
> > > var latlng = new google.maps.LatLng(48.130000, 25.570000);
> > >  var myOptions = {
> > >       zoom: 4,
> > >       center: latlng,
> > >       mapTypeId: google.maps.MapTypeId.HYBRID
> > >     };
> > >  var map = new google.maps.Map(document.getElementById("map_canvas"),
> > > myOptions);
>
> > > So - I should replace the LatLng(48.130000, 25.570000) with WHAT?
> > > and I should replace zoom: 4 with WHAT?
> > > I have made several attempts to get around this - but I'm probably too
> > > unfamiliar with javascript to figure it out. I would welcome every
> > > help with this matter.
> > > Thank you
> > > Lennarthttp://www.skof.se/fbo/aterfynd/min_phpsqlajax_map3.php-Dölj 
> > > citerad text -
>
> > - Visa citerad text -

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

Reply via email to