微信 jssdk获取经纬度转换成百度的经纬度

本文介绍如何使用微信JSSDK获取地理位置经纬度,并将其转换为百度地图的坐标,通过调用百度地图API进行地址解析,实现地理信息的定位与展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1:引入js文件

[php]  view plain  copy
  1. <script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>  
  2.   
  3. <script type="text/javascript" src="http://api.map.baidu.com/api?type=quick&ak=iT46LDMO8w4i3k6blFarL7Me9RC2yQ1r&v=1.0"></script>  


[php]  view plain  copy
  1. <script>  
  2.   wx.config({  
  3.     appId: '{{signPackage[0].appId}}',  
  4.     timestamp: {{signPackage[0].timestamp}},  
  5.     nonceStr: '{{signPackage[0].nonceStr}}',  
  6.     signature: '{{signPackage[0].signature}}',  
  7.     jsApiList: [  
  8.       // 所有要调用的 API 都要加到这个列表中  
  9.        'getLocation',  
  10.        'openLocation'  
  11.     ]  
  12.   });  
  13.   wx.ready(function () {  
  14.     // 在这里调用 API  
  15.         wx.getLocation({  
  16.                 success: function (res) {  
  17.                     var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90  
  18.                     var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。  
  19.                     var speed = res.speed; // 速度,以米/每秒计  
  20.                     var accuracy = res.accuracy; // 位置精度  
  21.                     localStorage.setItem("latitude", latitude);  
  22.                         localStorage.setItem("longitude", longitude);  
  23.                       
  24.                     //var data = {  
  25.                     //  latitude: latitude,  
  26.                     //  longitude: longitude  
  27.                     //};  
  28.                     // alert(JSON.stringify(data));  
  29.             $.ajax({  
  30.             url: 'http://api.map.baidu.com/geocoder/v2/?ak=btsVVWf0TM1zUBEbzFz6QqWF&callback=renderReverse&location=' + latitude + ',' + longitude + '&output=json&pois=1',  
  31.             type: "get",  
  32.             dataType: "jsonp",  
  33.             jsonp: "callback",  
  34.             success: function (data) {  
  35.                 console.log(data);  
  36.                 var name = (data.result.formatted_address);  
  37.                    
  38.                    
  39.                  //var map=JSON.stringify(name);  
  40.                              //alert(map);die;  
  41.                  //var map1=map.substr(1);  
  42.                  //var map1=name(start,stop);  
  43.                  //alert(name);die;  
  44.                    
  45.                  $("#txt_dw").val(name);    
  46.                     
  47.                 if (typeof callback == "function") {  
  48.                     callback(data);  
  49.                 }  
  50.   
  51.             }  
  52.          });  
  53.              //var map = new BMap.Map("allmap");  
  54.                      //var point = new BMap.Point(116.331398,39.897445);  
  55.                      //var gc = new BMap.Geocoder();  
  56.                      //gc.getLocation(point, function(rs){  
  57.                      //var addComp = rs.addressComponents;  
  58.                      //alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);  
  59.                      //});  
  60.                       
  61.   
  62.                  }  
  63.       
  64.   
  65.       
  66.                  });  
  67.     
  68.  });  
  69. </script>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值