|
amap 模块
// 获取定位
function getLocationAmap() {
map = api.require('aMap');
var mobile = $api.getStorage('mobile');
timer = setTimeout(function () {
getLocationAmap()
}, 60000);
map.getLocation({
enableLocInForeground: true,
notification: {
title: '新思路', //(可选项) 字符串类型;标题; 默认值:应用名称
content: '正在后台运行', //(可选项) 字符串类型;内容; 默认值:正在后台运行
channelId: '34', //字符串类型,通知通道号,argetSdkVersion大于等于28时必填
}
}, function (ret, err) {
if (ret.status) {
var lon = ret.lon;
var lat = ret.lat;
dw = gps_bgps(lon, lat)
// console.log(mobile + "获取定位:" + JSON.stringify(dw))
LocationAmap(mobile, dw.bd_lng, dw.bd_lat);
} else {
console.log(JSON.stringify(err));
}
});
}
//高德坐标转百度(传入经度、纬度)
function gps_bgps(gg_lng, gg_lat) {
var X_PI = Math.PI * 3000.0 / 180.0;
var x = gg_lng, y = gg_lat;
var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI);
var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI);
var bd_lng = z * Math.cos(theta) + 0.0065;
var bd_lat = z * Math.sin(theta) + 0.006;
return {
bd_lng: bd_lng,
bd_lat: bd_lat
};
}
// 打开高德地图 高德iOS定位必须
function openMap() {
map = api.require('aMap');
// console.log("打开地图")
//设置地图类隐私权限
map.updateMapViewPrivacy({
privacyAgree: 'didAgree',
privacyShow: 'didShow',
containStatus: 'didContain'
});
map.open({
rect: {
x: 0,
y: 0,
w: 0,
h: 0
},
showUserLocation: true,
zoomLevel: 11,
center: {
lon: 116.4021310000,
lat: 39.9994480000
},
fixedOn: api.frameName,
fixed: true
}, function (ret, err) {
// console.log("openmap:" + JSON.stringify(ret))
// console.log("openmap:" + JSON.stringify(err))
});
}
// 关闭地图
function closeMap() {
map = api.require('aMap');
map.close();
}
// 停止定位
function stopLocationAmap() {
clearTimeout(timer)
}
// 上传定位
function LocationAmap(iphone, lng, lat) {
console.log("发送请求")
dealData("driver/transport/reportLocation?mobile=" + iphone + "&lng=" + lng + "&lat=" + lat, 'GET', {},
function (ret) {
if (ret.status == 0) {
console.log(JSON.stringify(ret));
} else {
console.log("定位上传失败!");
return;
}
},
function (err) {
console.log(JSON.stringify(err));
// myAlert('服务器内部错误!');
})
}
|
|