Your code contains a possible conflict. This isn't generally possible

carte.fitBounds(bounds);
carte.setCenter(location);

If the new marker is too far away from the previous one it isn't
logically possible that the map fit the bounds and set the new center
simultaneously.
So the result would be unexpected.





On Jun 18, 10:15 am, olivier <[email protected]> wrote:
> I want to start from this example from the official doc 
> :http://code.google.com/intl/fr/apis/maps/documentation/javascript/eve...
> but i'd like to have the map resized and recentered automatically and
> optimally each time i add a new marker on the map. I thought
> fitBounds() was doing it, but it doesn't.
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml"; lang="fr" xml:lang="fr">
> <head>
> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
> <title>Google Maps test</title>
> <script src="http://maps.google.com/maps/api/js?sensor=false";
> type="text/javascript"></script>
> <script type="text/javascript">
> var carte;
> function initialize() {
>         var myLatlng = new google.maps.LatLng(46.824642494641,
> 2.02678155899047);
>         var myOptions = {
>                 zoom: 6,
>                 center: myLatlng,
>                 mapTypeId: google.maps.MapTypeId.ROADMAP
>         }
>         carte = new google.maps.Map(document.getElementById("map"),
> myOptions);
>         google.maps.event.addListener(carte, 'click', function(event) {
>                 placeMarker(event.latLng);
>         });}
>
> function placeMarker(location) {
>         var clickedLocation = new google.maps.LatLng(location);
>         var marker = new google.maps.Marker({
>                 position: location,
>                 map: carte
>         });
>         var bounds = carte.getBounds();
>         bounds.extend(location);
>         carte.fitBounds(bounds);
>         carte.setCenter(location);}
>
> </script>
> </head>
> <body onload="initialize();">
> <div id="map" style="width: 600px; height: 450px"></div>
> </body></html>
>
> Can you help me out. Thanks a lot

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