查看: 747|回复: 0

微信jssdk定位

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2024-5-26 13:12:12 | 显示全部楼层 |阅读模式
  1. wx.ready(function(){
  2.         var located = "{$_GPC['located']}";
  3.         if(!located){
  4.             getLocation();
  5.         }
  6.     });
  7.     //JSSDK调用失败时触发
  8.     wx.error(function(res){
  9.         console.log(res)
  10.     });
  11.     //定位
  12.     function getLocation() {
  13.         wx.getLocation({
  14.             // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  15.             type: 'gcj02',
  16.             success: function (res) {
  17.                 var latitude = res.latitude;
  18.                 var longitude = res.longitude;
  19.                 var speed = res.speed;
  20.                 var accuracy = res.accuracy;
  21.                 var params = {
  22.                     'latitude': latitude,
  23.                     'longitude': longitude
  24.                 }
  25.                 localStorage.latitude = latitude;
  26.                 localStorage.longitude = longitude;
  27.                 $.post("{php echo $this->createMobileUrl('locate')}", params, function(res){
  28.                     var data = $.parseJSON(res);
  29.                     if(data.message.errno < 0){
  30.                         $.alert(data.message.message, '温馨提示', function(){
  31.                             window.location.href = data.redirect;
  32.                         });
  33.                     } else {
  34.                         $.showLoading();
  35.                         setTimeout(function() {
  36.                             $.hideLoading();
  37.                         }, 3000);
  38.                         window.location.href = data.redirect;
  39.                     }
  40.                 });
  41.             }
  42.         });
  43.     }
复制代码


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

本版积分规则

关注公众号

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

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

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