javascript - google heatmaps including count of points -
i have working code google heatmap. quick overview of does:
1) queries mysql db pull lat/long records (initially) 2) drop down select box allows filtering (basically amends sql query in php) 3) heatmap json array (using php json_encode($sql_results))
so code have right works - however, wish add more map.
my question - possible pull count of results particular location (i'm using postal code generate lat/long) , display them on heatmap?
an example ; 100 results location x ... , zoom in , dissipate heatmap, amend number.
i have tried looking similar functionality can find information on adding markers/images results - need dynamic numbers displaying results.
any help/advice appreciated.
here's relevant code used create heatmap:
<?php $latlng = "select inp.lat, inp.long locations inp"; $results = db_query($latlng); $mapcoords = mysqli_fetch_all($results, mysqli_assoc); ?> <script type="text/javascript"> var places = []; var coords = <?php echo json_encode($mapcoords); ?>; (var = 0; < coords.length; i++) { places.push(new google.maps.latlng(coords[i].lat, coords[i].long)); } var map, pointarray, heatmap; var gradient = [ 'rgba(0, 255, 255, 0)', 'rgba(0, 255, 255, 1)', 'rgba(0, 191, 255, 1)', 'rgba(0, 127, 255, 1)', 'rgba(0, 63, 255, 1)', 'rgba(0, 0, 255, 1)', 'rgba(0, 0, 223, 1)', 'rgba(0, 0, 191, 1)', 'rgba(0, 0, 159, 1)', 'rgba(0, 0, 127, 1)', 'rgba(63, 0, 91, 1)', 'rgba(127, 0, 63, 1)', 'rgba(191, 0, 31, 1)', 'rgba(255, 0, 0, 1)' ]; var data = places; function initialize() { var mapoptions = { zoom: 6, center: new google.maps.latlng(54.892473,-2.932931), maptypeid: google.maps.maptypeid.roadmap }; map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); pointarray = new google.maps.mvcarray(data); heatmap = new google.maps.visualization.heatmaplayer({ data: pointarray, dissipating: true, radius: 35 }); heatmap.setmap(map); heatmap.set('gradient', heatmap.get('gradient') ? null : gradient); heatmap.set('opacity', '0.9'); } google.maps.event.adddomlistener(window, 'load', initialize); </script>
so, think looking @ wrong approach - initial idea pull count db of returned rows , display custom marker dynamic text. solution found (and simple implement!) google marker clustering using markerclusterer.js. me, downloaded js, pointed in code , added following:
<script type="text/javascript" src="markerclusterer.js"></script> var places = []; var markers = []; var coords = <?php echo json_encode($mapcoords); ?>; (var = 0; < coords.length; i++) { places.push(new google.maps.latlng(coords[i].lat, coords[i].long)); var latlng = new google.maps.latlng(coords[i].lat, coords[i].long); var marker = new google.maps.marker({'position': latlng}); markers.push(marker); }
`
and @ end set cluster , add options:
var mcoptions = {gridsize: 50, maxzoom: 15}; var markercluster = new markerclusterer(map, markers, mcoptions);
that's pretty - zoom in change in counts , need work on custom markers infowindows. hope helps else in same situation.
Comments
Post a Comment