View Single Post
Old 09-04-2012, 05:11 PM   PM User | #10
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
You're not listening. hObj is just an object, and every time the loop iterates it gets overwritten. That's why you need to push it onto an array (inside the loop) and then pass the array to the heatMapLayer (outside the loop).

I would try this:

Code:
<!DOCTYPE html>
  <head>
    <meta charset="utf-8">
    <title>Google Maps JavaScript API v3 Example: Heatmap Layer</title>
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map { height: 100%;
      float:right; }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=visualization"></script>
<script type="text/javascript">
var heatMapData=[]//empty array to store objects

function initialize() {
        var mapOptions = {
          zoom: 5,
          center: new google.maps.LatLng(21.1438, 79.0926),
          mapTypeId: google.maps.MapTypeId.SATELLITE
        };
        downloadUrl("phpsqlajax_genxml.php", function(data) {
           var xml = data.responseXML;
           var markers = xml.documentElement.getElementsByTagName("marker");
  for (var i = 0; i < markers.length; i++) { //loop through nodes getting info
    var int = markers[i].getAttribute("intensity");
    var point = new google.maps.LatLng(
        parseFloat(markers[i].getAttribute("lat")),
        parseFloat(markers[i].getAttribute("lng")));
    var hObj = { //create object
      location: point,
      weight: int
    }
heatMapData.push(hObj); //push object onto array
}
}
         pointArray = new google.maps.MVCArray(heatMapData); //convert array to MVC array

        heatmap = new google.maps.visualization.HeatmapLayer({
          data: pointArray
        }); //create heat map object

        heatmap.setMap(map); //display heat map on map
}
</script>
</head>
<body onload="initialize()">
    <div id="map" style="height: 600px; width: 800px;"></div>
  </body>
</html>
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
egregious (09-04-2012)