查看: 724|回复: 0

非微信浏览器定位

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2024-5-26 12:57:24 | 显示全部楼层 |阅读模式
  1. {if $_W['container'] != 'wechat'}
  2. <script src="https://mapapi.qq.com/web/mapComponents/geoLocation/v/geolocation.min.js"></script>
  3. <script>
  4.     var geolocation = new qq.maps.Geolocation("{$system['qqmapkey']}", "myapp");
  5.     {if empty($_GPC['located']) && $_GPC['do'] != 'city'}
  6.     $.confirm('为给您提供更好的服务,请授权我们获取您的位置信息', '用户位置请求', function() {
  7.         geolocation.getLocation(showPosition, showErr, {timeout: 8000});
  8.     });
  9.     function showPosition(position) {
  10.         //console.log(position);
  11.         /**
  12.          * position.lat//纬度
  13.          * position.lng//经度
  14.          * position.adcode//行政区划代码
  15.          * position.addr//定位地址
  16.          * position.nation//国家
  17.          * position.province//省份
  18.          * position.city//城市
  19.          * position.district//地区
  20.          */
  21.         //定位请求
  22.         $.post("{php echo $this->createMobileUrl('store', array('op'=>'locate'))}", {lat: position.lat, lng: position.lng}, function(res) {
  23.             var data = $.parseJSON(res);
  24.             if (data.message.errno < 0) {
  25.                 $.alert(data.message.message, 'text');
  26.                 return;
  27.             } else {
  28.                 $.toast(data.message.message, 'text');
  29.                 window.location.reload();
  30.             }
  31.         });
  32.     }
  33.     function showErr() {
  34.         console.log('定位失败');
  35.     }
  36.     {/if}
  37. </script>
  38. {/if}
复制代码


道不同,不相为谋!理想要有,万一实现了呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:2513533699@qq.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鲁ICP备19000917号|鲁公网安备37078302000320号

在本版发帖
关注公众号
QQ客服返回顶部