hi,

if i specify the bounds.extend(point) with actual values am getting
the zoom centered around it....
but not with the case with bounds.extend(point) inside for loop....

like this....

<script type="text/javascript">
    var marker;
    var infowindow;

 var customIcons = {
      1: {
        icon: 'http://10.7.225.48/BSNL/images/mm_20_blue.png',
        shadow: 'http://labs.google.com/ridefinder/images/
mm_20_shadow.png'
      },
      2: {
        icon: 'http://labs.google.com/ridefinder/images/
mm_20_red.png',
        shadow: 'http://labs.google.com/ridefinder/images/
mm_20_shadow.png'
      }
    };

    function initialize() {
      var latlng = new google.maps.LatLng(16.9538059, 77.5968833);
      var options = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      var map = new
google.maps.Map(document.getElementById("map_canvas"), options);
      var html = "<table>" +
                 "<tr><td>Name:</td> <td><input type='text' id='name'/
> </td> </tr>" +
                 "<tr><td>Address:</td> <td><input type='text'
id='address'/></td> </tr>" +
                 "<tr><td>Type:</td> <td><select id='type'>" +
                 "<option value='1' SELECTED>bar</option>" +
                 "<option value='2'>restaurant</option>" +
                 "</select> </td></tr>" +
                 "<tr><td></td><td><input type='submit' value='Save &
Close' onclick='saveData()'/><input type='hidden' name='txtUpdate'
value='update' /></td></tr></table>";
    infowindow = new google.maps.InfoWindow({
     content: html
    });

    google.maps.event.addListener(map, "click", function(event) {
        marker = new google.maps.Marker({
          position: event.latLng,
          map: map
        });
        google.maps.event.addListener(marker, "click", function() {
          infowindow.open(map, marker);
        });
    });

    var infoWindowLM = new google.maps.InfoWindow;

                var bounds = new google.maps.LatLngBounds();

              downloadUrl("/BSNL/COMPANY/home/landmark_genxml.asp",
function(data) {
                var xml = parseXml(data);
                var markers =
xml.documentElement.getElementsByTagName("marker");

                for (var i = 0; i < markers.length; i++) {
                  var name = markers[i].getAttribute("name");
                  var address = markers[i].getAttribute("address");
                  var type = markers[i].getAttribute("type");
                  var latit = parseFloat(markers[i].getAttribute("lat"));
                  var longi = parseFloat(markers[i].getAttribute("lng"));
                  var point = new
google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
                  var htmlLM = "<b>" + name + "</b> <br/>" + address;
//alert(latit+","+longi);
                  var icon = customIcons[type] || {};
                  var markerLM = new google.maps.Marker({
                    map: map,
                    position: point,
                    icon: icon.icon,
                    shadow: icon.shadow
                  });
                  bindInfoWindow(markerLM, map, infoWindowLM, htmlLM);
                          bounds.extend(point);
                        //  alert(latit+","+longi);
                        //  alert(point);

                }

              });
              //bounds.extend(10.554761,75.883016);
              //bounds.extend(17.625156,83.002157);
              //bounds.extend(12.706773,80.277547);
              //bounds.extend(12.621021,77.728719);
              //bounds.extend(17.205849,78.871297);
              //bounds.extend(18.460832,72.982625);

              map.fitBounds(bounds);
              //map.setCenter(bounds.getCenter());
              map.setCenter(bounds.getCenter(),
map.getBoundsZoomLevel(bounds));


    }

    function saveData() {
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var type = document.getElementById("type").value;
      var latlng = marker.getPosition();
        //var txtUpdate = escape(document.getElementById("txtUpdate").value);

      var url = "/BSNL/COMPANY/home/AddLandmark.asp?name=" + name +
"&address=" + address +
                "&type=" + type + "&lat=" + latlng.lat() + "&lng=" +
latlng.lng();
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200 && data.length <= 1) {
          infowindow.close();
          document.getElementById("message").innerHTML = "Location
added.";
        }
      });
    }

function creat_Object()
{
                if (window.XMLHttpRequest)
                {
                        req = new XMLHttpRequest();
                }
// else condition for ie

                else
                {
                req = new ActiveXObject("Microsoft.XMLHTTP");
                }
                return req;
};


    function downloadUrl(url, callback) {
      var request = creat_Object();

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request.responseText, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }

function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

    function parseXml(str) {
      if (window.ActiveXObject) {
        var doc = new ActiveXObject('Microsoft.XMLDOM');
        doc.loadXML(str);
        return doc;
      } else if (window.DOMParser) {
        return (new DOMParser).parseFromString(str, 'text/xml');
      }
    }


    function doNothing() {}
    </script>
</head>
<body onload="initialize();">

.....


what could be the issue...

in chrome its working if i reload the page again (2nd time)....but not
in firefox, opera.....

pls help me.

On Apr 4, 12:22 pm, Ashwin <[email protected]> wrote:
> HI,
>
> This is the way i tried.....
>
> http://218.248.72.237/BSNL/COMPANY/home/displaypoi.asp
>
> its centering the map some where else instead of the marked points....
>
> what is the mistake am making...
>
> On Apr 4, 8:13 am, Ashwin <[email protected]> wrote:
>
>
>
> > hi,
>
> > Gmaps V3..
>
> > Pls give me some guidance to get my Gmaps centered around the markers
> > loaded from the db as explained in the following link
>
> >http://code.google.com/apis/maps/articles/phpsqlajax_v3.html
>
> > i need to dynamically set the zoom level and centering the map around
> > the marker bounds....pls provide me some example or link to a page
> > where its explained....i googled it around ...but finding usage
> > scenario mostly for V2...
>
> > with regards
>
> > Ashwin

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