小编Ste*_*e C的帖子

设置leaflet.js地图以显示当前位置

我正在使用leaf的leaflet.js包,我在初始渲染时将地图默认设置为当前位置时遇到问题.setView方法适用于硬数字,但它不喜欢我的变量.我对js很新,所以错误很明显.这就是我所拥有的:

 Template.map.rendered = function() {
 L.Icon.Default.imagePath = 'packages/bevanhunt_leaflet/images';

 if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    console.log('--- Your Position: ---');
    console.log('Lat: ' + position.coords.latitude);
    latit = position.coords.latitude;
    console.log('Long: ' + position.coords.longitude);
    longit = position.coords.longitude;
    console.log('---------------------');
    var abc = L.marker([position.coords.latitude, position.coords.longitude]).addTo(map);
} 
)}

map = L.map('map', {
  doubleClickZoom: false
}).setView([latit, longit], 13);
Run Code Online (Sandbox Code Playgroud)

我不断得到的错误是

Uncaught TypeError: Cannot read property 'addLayer' of undefined
L.Marker.L.Class.extend.addTo @ leaflet-src.js:3511
(anonymous function) @ client.js?ea76789cca0ff64d5985320ec2127d5de1fb802f:28
Run Code Online (Sandbox Code Playgroud)

当我在console.log(latit)或console.log(longit)时,它返回数字,以及之后的"undefined".提前感谢任何可以帮助您的人!

编辑:

初始渲染时的确切控制台输出:

Exception from Tracker afterFlush function:
debug.js:41 ReferenceError: latit is not defined
    at Template.map.rendered …
Run Code Online (Sandbox Code Playgroud)

javascript undefined leaflet meteor

3
推荐指数
2
解决办法
8787
查看次数

N /(2N - 1)的递归求和

对于正整数N,我想要求和的总和1/1 + 2/3 + ... + N/(2N-1).

我的递归Sum方法停留在无限循环上,我不知道为什么.打印出变量时,我注意到first(我的参数)正在增加.value永远不会达到增量的声明.

public double Sum(double first) {

    if (first > 1) {
     System.out.println("first :" + first);
     value  +=   first / ( Sum(2*first - 1) + Sum(first-1) );
     System.out.println("val: " + value);
     return value;
    }

   if (first <= 1) {
       return 1;
    }
  else {
      return value;
  }

}
Run Code Online (Sandbox Code Playgroud)

java recursion

0
推荐指数
1
解决办法
106
查看次数

标签 统计

java ×1

javascript ×1

leaflet ×1

meteor ×1

recursion ×1

undefined ×1