简体   繁体   English

HTML5和地理位置

[英]HTML5 and geolocation

I want to get my position each timeinterval using navigator.geolocation.watchPosition Later on I want to store these coordinates in a xml file. 我想使用navigator.geolocation.watchPosition每次获取时间间隔的位置,稍后再将这些坐标存储在xml文件中。

The problem is the watchPosition function does not call the getLocation function. 问题是watchPosition函数没有调用getLocation函数。

  function trackCoords ()
  {
      if (navigator.geolocation)
      {

          var options = { frequency: 3000 };
            watchID = navigator.geolocation.watchPosition(getLocation, locationFail, options);
      }


  }



  function getLocation(position) { 
        alert();
        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;
        alert('latitude: ' + latitude + ' longitude: ' + longitude);
        }

    function locationFail() {
    document.write('We did not get your location');
            }

Thanks in advance 提前致谢

I think you're not calling trackCoords. 我想您不是在打电话给trackCoords。 Does the browser ask you for permission to be geolocalized? 浏览器是否要求您进行地理定位的许可? If I add trackCoords() at the end of your script it seems to work for me: 如果我在脚本的末尾添加trackCoords() ,似乎对我trackCoords()

http://codepen.io/jonigiuro/pen/vCBsk http://codepen.io/jonigiuro/pen/vCBsk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM