敬告:此 demo 演示为开放测试页面,仅用于开发者快速测试体验应用功能,请严格遵守开发者协议,威尼斯人888-5845vip威尼斯电子游戏。
♦ js-sdk 引用方式:
♦ 普通网页 script 方式加载:下载最新版 ,请在页面上调用 jsbridge 接口之前引用 jsbridge-mini.js 库;
♦ js module 方式引用:npm install ym-jsbridge
单次定位,返回 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);
});
//示例定位结果(模拟数据):
var sample =
{
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 回调参数):