【实用随记】浏览器端定位
来源:互联网 发布:炮哥捏脸数据 编辑:程序博客网 时间:2024/06/04 17:51
手里的项目是webApp,用的 webViews。
第一个BETA版是在客户端做定位,我与安卓和IOS传参交互觉得很麻烦,但苦于没有时间,今天终于得空,研究一下浏览器端定位。
用的百度开发者地图API。
<div id="latitude"></div> <div id="longitude"></div> <div id="reverseSampleUrl"></div> <div id="reverseNarrative"></div>
var geol; var nowLo; var nowLa; try { if (typeof(navigator.geolocation) == 'undefined') { geol = google.gears.factory.create('beta.geolocation'); } else { geol = navigator.geolocation; } }catch (error) { //alert(error.message); } if (geol) { geol.getCurrentPosition(function(position) { var nowLatitude = position.coords.latitude; var nowLongitude = position.coords.longitude; //alert("纬度:" + nowLatitude + ", 经度:" + nowLongitude); $('#latitude').html(nowLatitude); $('#longitude').html(nowLongitude); nowLa = nowLatitude; nowLo = nowLongitude; //alert(nowLa); doReverse(); }, function(error) { switch(error.code){ case error.TIMEOUT : alert("连接超时,请重试"); break; case error.PERMISSION_DENIED : alert("您拒绝了使用位置共享服务,查询已取消"); break; case error.POSITION_UNAVAILABLE : alert("非常抱歉,我们暂时无法通过浏览器获取您的位置信息"); break; } }, {timeout:10000}); //设置十秒超时 } function doReverse() { document.getElementById('reverseNarrative').innerHTML = ''; var script = document.createElement('script'); script.type = 'text/javascript'; script.src =' http://api.map.baidu.com/geocoder/v2/?ak=你的密钥(百度注册一个开发者账号)&callback=renderReverse&location=' +nowLa+',' + nowLo +'&output=json&pois=0;' document.body.appendChild(script); }; function renderReverse(response) { var html = ''; if (response.status ) { //alert(response.status); var text = "1234567:\n"; document.getElementById('reverseNarrative').innerHTML = text; return; } var location = response.result.location; html = "城市: "+ response.result.addressComponent.city; document.getElementById('reverseNarrative').innerHTML = html; return; }
0 0
- 【实用随记】浏览器端定位
- 【实用随记】absolute定位中的横向居中
- 【实用随记】js判断设配及浏览器
- 【实用随记】头像区域
- 【实用随记】背景图片翻转
- 【实用随记】表单什么的
- 【实用随记】表单验证
- 【实用随记】进度条
- 【实用随记】js日历
- 【实用随记】touch事件
- 【实用随记】手风琴折叠
- 【实用随记】解决不同浏览器字符间距不同的四个属性
- 【实用随记】JQuery事件绑定
- 【实用随记】JQ表单验证
- 【实用随记】JS全选反选不选
- 【实用随记】前台实现查找
- 【实用随记】缩略显示文件名
- 【实用随记】js菜单联动
- C++学习笔记 数据类型
- Solr 3.6.1 官方教程翻译(转载)
- sencha touch routes(路由) 传递中文参数
- 【Maven】Archetype
- 转载和积累系列 - CentOS 网络配置
- 【实用随记】浏览器端定位
- zigbee事件
- 关于intent中传输字符串丢失的解决…
- adb pull/push
- cf 431D 二分+数位DP
- 转:ubuntu修改计算机名和加入wind…
- 华为2014机考题:输入1--50个数字,求出最小数和最大数的和
- 转:Ubuntu上可使用的15个桌面环境
- 转:Windows 7硬盘安装Ubuntu…