码迷,mamicode.com
首页 > 移动开发 > 详细

移动网页 -- 设备-地理定位

时间:2016-06-14 00:51:50      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:

1、地理定位

1 navigator.geolocation.getCurrentPosition(function(where){
2    alert(where.coords.latitude + "," + where.coords.longitude);
3 })
1 var geo = navigation.geolocation,
2       lcn_success = function(where){},
3       lcn_error = function(){};
4 geo.getCurrentPosition(lcn_success ,lcn_error );

定位操作时刻发生watchPosition:

1  navigator.geolocation.watchPosition(function(where){
2      alert(where.coords.latitude + "," + where.coords.longitude);
3  })

取消查看用户的定位信息,需要使用具有独立ID的clearWatch()类函数:

1 var geo = navigation.geolocation,
2      watchID = geo.watchPosition(),
3      endWatch = document.getElementById("stop");
4 endWatch.addEventListener(‘click‘,function(){
5      geo.clearWatch(watchID);
6 },false)

移动网页 -- 设备-地理定位

标签:

原文地址:http://www.cnblogs.com/zhanghuiyun/p/5553985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!