使用W3C GeoLocation API'的watchPosition函数
Using the W3C GeoLocation API's watchPosition function
我不知道如何使用W3C GeoLocation API来观察用户的位置。最简单的方法是什么?我想要的只是更新用户的纬度和经度。
我刚刚在一个项目中使用了这个,我通过Ben Nadel的博客文章和API本身解决了这个问题。
navigator.geolocation.watchPosition(function(position){
// These variables update every time the location changes
var Latitude = position.coords.latitude;
var Longitude = position.coords.longitude;
}, function(error){
// You can detect the reason and alert it; I chose not to.
alert('We could not get your location');
},{
// It'll stop looking after an hour. Enabling high accuracy tells it to use GPS if it's available
timeout: 5000,
maximumAge: 600000,
enableHighAccuracy: true
});
希望这对你有帮助!
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 如何在JavaScript中将字符串转换为函数引用
- 用嵌套函数和默认函数定义函数
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- JQuery合并了keyup和focusout两个函数
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 我可以在json对象中添加一个函数吗
- AngularJS:我可以跳过函数参数回调吗
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- jquery点击函数select&取消选择
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- Node.js v6.2.0类扩展不是函数错误
- 有人能告诉我如何使用getCurrentPosition的watchposition()函数吗
- 如何使用WatchPosition()函数Geolocation来观察其他坐标
- 使用W3C GeoLocation API'的watchPosition函数