1

我正在尝试根据我拥有的一些数据在 Google Maps API 上创建一个热图图层。这是基于 Google Maps API v3 文档:

https://developers.google.com/maps/documentation/javascript/layers#JSHeatMaps

问题是如果我必须添加新数据,我必须在代码本身中编写它。纬度、经度和重量。我已经设法将 PHP 的 XML 输出导入 JavaScript 用于另一个目的,我认为这也可以用于热图层。但是,我的代码根本无法正常工作。图层没有显示,只有地图来了。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Heatmap Layer</title>
<link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="https://maps.googleapis.com/maps/api/js?
v=3.exp&sensor=false&libraries=visualization"></script>
<script>
// var map, pointarray, heatmap;
var heatMapData = [];

function initialize() {
    var mapOptions = {
      zoom: 8,
      center: new google.maps.LatLng(23.2500, 87.8500),
      mapTypeId: google.maps.MapTypeId.ROADMAP,
     };

    var map = new google.maps.Map(document.getElementById('map_canvas'),
        mapOptions);


 downloadUrl("phpsqlajax_genxml_heatmap.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 point = new google.maps.LatLng(
    parseFloat(markers[i].getAttribute("lat")),
    parseFloat(markers[i].getAttribute("lng")));
    var intensity = markers[i].getAttribute("intensity");
 var hObj = { //create object
  location: point,
  weight: intensity
 }
 heatMapData.push(hObj); //push object onto array  

 }
 });

    //pointArray = new google.maps.MVCArray(heatMapData);

    var heatmap = new google.maps.visualization.HeatmapLayer({
    data: heatMapData,
    dissipating: true,
    radius: 150,
    maxIntensity: 200
    });

    heatmap.setMap(map);
  }

function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

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

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

</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="height: 600px; width: 800px;"></div>
</body>
</html>

我使用 Google 的参考资料将 XMP 从 PHP 导入 JavaScript:

有人能帮帮我吗?

提前致谢...

4

0 回答 0