作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 google.maps.visualization 库。我已经在我的代码中包含了这个库,而且大部分似乎都在工作,但是当我开始创建热图时,我收到一个关于“位置 96677 的值无效:[object Object]”的错误.我不确定这个问题是什么,但错误报告包含一行 Google API 代码:
var c;
M(b,function(b,e){
try{
a(b)||(c="Invalid value at position "+(e+(": "+b)))
}catch(f){
c="Error in element at position "+(e+(": ("+(f[Pb]+")")))}});c&&aa(ja(c));return j
}
}
$.ajax({
url: "../Yield/getYieldData.php",
success: function(text) {
var data;
// var yieldPoints = new google.maps.MVCArray();
var yieldPoints = [];
try{
data = $.parseJSON(text);
} catch (e) {
alert("ERROR: " + e);
}
for(i=0; i < data.points.length; i++) {
// yieldPoints.push({ location: new google.maps.LatLng(data.points[i].lat, data.points[i].lon), weight: data.points[i].yield });
yieldPoints[i] = { location: new google.maps.LatLng(data.points[i].lat, data.points[i].lon), weight: data.points[i].yield };
}
var heatMap = new google.maps.visualization.HeatmapLayer({ data: yieldPoints });
heatMap.setMap(map);
}
});
{"points":[{"lat":"38.1513366000","lon":"-97.4341659000","yield":"0"},{"lat":"38.1513748000","lon":"-97.4341125000","yield":"0"},{"lat":"38.1513938000","lon":"-97.4341125000","yield":"0"},{"lat":"38.1493263000","lon":"-97.4339447000","yield":"0"},{"lat":"38.1493339000","lon":"-97.4339447000","yield":"0"},{"lat":"38.1493377000","lon":"-97.4339447000","yield":"0"},{"lat":"38.1483650000","lon":"-97.4358291000","yield":"0"},{"lat":"38.1484031000","lon":"-97.4358062000","yield":"0"},
最佳答案
weight
应该是 Number
,不是 String
.所以你有2个选择:
{"lat":"38.1513366000","lon":"-97.4341659000","yield":0}
//no quote wraps 'yield' ------------^
yield
至Number
:yieldPoints[i] = {
location: new google.maps.LatLng(data.points[i].lat, data.points[i].lon),
weight: +data.points[i].yield };
}; ^----- plus('+') is the fastest way for converting string to number
关于google-maps - 谷歌地图 API v 3 : Heatmap Creation Issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11296510/
leaflet:一个开源并且对移动端友好的交互式地图 JavaScript 库 中文文档: https://leafletjs.cn/reference.html 官网(英文): ht
我是一名优秀的程序员,十分优秀!