Lon*_*275 5 javascript maps google-maps heatmap google-maps-api-3
我使用 google 地图 js api 绘制了热图。所有位置都经过加权,并且希望颜色代表权重,而不是我得到一个红点,它会逐渐变成黄色,然后变成绿色。这不仅仅是一个测试,我将从数据库中填充邮政编码和重量
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=visualization"></script>
Run Code Online (Sandbox Code Playgroud)
。
function initialize() {
geocoder = new google.maps.Geocoder();
var mapProp = {
center:new google.maps.LatLng(40.785091,-73.968285),
zoom:11,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
codeAddress("10001", 6119);
codeAddress("10002", 5180);
codeAddress("10003", 4110);
codeAddress("10004", 899);
codeAddress("10005", 520);
codeAddress("10006", 599);
function codeAddress(zip, noAccidents) {
//var address = document.getElementById("address").value;
geocoder.geocode( { 'address': zip}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var hotSpot = results[0].geometry.location;
console.log(hotSpot + " " + noAccidents);
var heatMapZip = [
{location: hotSpot, weight: noAccidents}
];
var color =[
"#ff0000",
"#00ff00"
];
var heatmap = new google.maps.visualization.HeatmapLayer({
data: heatMapZip,
radius: 50,
dissapating: false
});
heatmap.setMap(map);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
Run Code Online (Sandbox Code Playgroud)

您应该使用该函数heatmap.set('gradient', gradient);来设置热图的颜色。颜色可以通过事故的# 以及数据集中# 的最大值和最小值来计算。
我为此创建了一个小提琴,希望它有所帮助。
| 归档时间: |
|
| 查看次数: |
10413 次 |
| 最近记录: |