问题描述
我一直在努力弄清楚为什么我的加热层遇到上述问题.我在坐下时看到的答案解决了不正确的LatLng设置,但是我的标记器的LatLng数组工作得很好.
I'm stuck trying to figure out why I'm getting the above issue for my heat-layer. The answers I've seen on while seatching address improper LatLng setup, however my marker's LatLng array work just fine.
即使api说它是可选的,我也尝试过添加权重.
I've tried adding weights as well even though the api say it's optional.
var map;
function initMap(resultSet) {
map = new google.maps.Map(document.getElementById('maps'), {
center: {
lat: 40.8173,
lng: -96.7005
},
zoom: 16,
mapTypeId: 'satellite'
});`
var labels = [];
var locations = [];
for (var i = 0; i < resultSet.length; i++) {
labels.push(resultSet[i][0]);
locations.push({
lat: parseFloat(resultSet[i][3]),
lng: parseFloat(resultSet[i][4])
});
if (data[0] == '1') {
var marker = new google.maps.Marker({
position: locations[i],
map: map,
title: labels[i]
});
marker.setMap(map);
}
}
if (data[0] == '2') {
var heatmap = new google.maps.visualization.HeatmapLayer({
data: locations,
});
heatmap.setMap(map);
}
}
推荐答案
HeatmapLayer
是您不能使用 google.maps.LatLngLiteral
的位置,必须 google.maps.LatLng
对象.(您得到的错误是因为匿名对象 LatLngLiteral
没有 .lat()
方法,它具有 .lat
属性)
The HeatmapLayer
is one of the remaining places you can't use a google.maps.LatLngLiteral
for a position, it must be a google.maps.LatLng
object.(the error you get is because the anonymous object LatLngLiteral
doesn't have a .lat()
method, it has a .lat
property).
更改:
for (var i = 0; i < resultSet.length; i++) {
labels.push(resultSet[i][0]);
locations.push({
lat: parseFloat(resultSet[i][3]),
lng: parseFloat(resultSet[i][4])
});
if (data[0] == '1') {
var marker = new google.maps.Marker({
position: locations[i],
map: map,
title: labels[i]
});
marker.setMap(map);
}
}
收件人:
for (var i = 0; i < resultSet.length; i++) {
labels.push(resultSet[i][0]);
locations.push(new google.maps.LatLng(
parseFloat(resultSet[i][3]),
parseFloat(resultSet[i][4])
));
if (data[0] == '1') {
var marker = new google.maps.Marker({
position: locations[i],
map: map,
title: labels[i]
});
marker.setMap(map);
}
}
这篇关于TypeError:b.lat不是函数-热图图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!