我有这段代码:
...
console.log(place.geometry.location.lat() + " lrdrdr " + place.geometry.location.lng());
var lat = place.geometry.location.lat();
var lon = place.geometry.location.lng();
write_points(lat, lon, const_lat, const_lon);
}
function write_points(starting_lat, starting_lon, constant_lat, constant_lon) {
var counter = 1;
for (var i = 1; i < 6; i++) {
var starting_lon_var = starting_lon + constant_lon * (i * Math.random());
console.log(starting_lat + " lahdeedah " + starting_lon_var);
...
这是控制台输出:
42.247865 lrdrdr -71.17272600000001
42.247865 lahdeedah NaN
为什么lrdrdr
(-71.17272600000001
)之后的值在被调用的write_points
函数中变为NaN。我将其作为参数(starting_lon
)传递,并通过此starting_lon + constant_lon * (i * Math.random())
计算,然后在输出时,由于某种原因它会给出NaN
。
答案 0 :(得分:0)
检查所有变量的另一个案例 - const_lon
被创建为NaN
,因为其争议涉及另一个变量。