好商城App 快捷打包
百度地理定位
♦ JS-SDK,下载最新版 jsBridge-v20200917.zip,请在页面上调用 jsBridge 接口之前引用 jsbridge-mini.js 库。
单次定位,返回 BD09ll 百度经纬度坐标,可以直接标记在百度地图上。
$("#cnt").hide(); var result = $("#result").text("定位中..."); $('html,body').animate({scrollTop: $('#view').offset().top}, 1200); //发起定位 jsBridge.bdloc.getCurrentPosition({ //可选,设置返回经纬度坐标类型,默认 GCJ02 //GCJ02: 国测局坐标 //BD09LL: 百度经纬度坐标 //BD09: 百度墨卡托坐标 //WGS84: GPS地心坐标 //海外地区定位统一返回 WGS84 地心坐标 coorType: 'BD09LL', //可选, 连续定位, 当位置变化时会收到回调通知, 默认 false //调用 jsBridge.bdloc.stop() 停止观察 watch: false }, function(position) { result.JSONView(position); }); /* 示例定位结果(模拟数据): { "success": true, "locType": 161, "locTypeDescription": "NetWork location successful!", "coorType": "bd09ll", "latitude": 30.596578, "longitude": 103.923732, "altitude": 5e-324, "adCode": "510122", "streetNumber": "", "street": "蜀都大道人民东路", "district": "成华区", "city": "成都市", "cityCode": "75", "province": "四川省", "country": "中国", "countryCode": "0", "locationDescribe": "天府广场附近", "poi": [{ "id": "624481706965053890", "name": "天府广场", "reliability": 0.99 }, { "id": "11831156867791473252", "name": "四川科技馆", "reliability": 0.99 }, { "id": "17660247562227023871", "name": "锦城艺术宫", "reliability": 0.99 }, { "id": "9997345703234431722", "name": "仁和春天百货", "reliability": 0.99 }, { "id": "17995585118206427135", "name": "成都博物馆新馆", "reliability": 0.99 }], "locationID": "r_Oy4Dz7t_fp9uDz-tTxgrji7uzp6-bo4bO2xeW3tbPUif7626qv-tH19vOjdaeDMz9fDzNfBlIaRxZ6WkLbs7N3ClBwO" }; */
watch 参数设为 true 即为实时连续定位,当用户位置发生变化时会收到回调通知。
var i = 0; var cnt = $("#cnt").show().text(""); var result = $("#result").text("定位中..."); $('html,body').animate({scrollTop: $('#view').offset().top}, 1200); //发起定位,开启后请拿着手机走起来 //在室外开启GPS定位会更准确 jsBridge.bdloc.getCurrentPosition({ coorType: 'BD09LL', watch : true }, function(position){ cnt.text("第几次位置变化通知: " + (++i)); result.JSONView(position); });
停止定位
//停止定位 jsBridge.bdloc.stop();
定位结果 (position 回调参数):