mobilemode.api.lbs4amap_wev8.js
2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
define("mApi/lbs4amap", ["mUtil", "amap"], function(mUtil) {
var callbackStack = [];
return {
getCurrPosition: function(callback, type){
callbackStack.push(callback);
function transformLL(longitude, latitude){
var parseResult = function(addr, addrComp){
callbackStack.forEach(function(cb) {
cb && cb({
status: "1",
errMsg: "",
lng: longitude,//经度
lat: latitude,//纬度
addr: addr,//中文地址
province: addrComp.province,//省份
city: addrComp.city,//城市
district: addrComp.district,//区
street: addrComp.street,//街道
streetNumber: addrComp.streetNumber//街道号码
});
});
callbackStack = [];
};
AMap.plugin('AMap.Geocoder', function() {
var geocoder = new AMap.Geocoder();
geocoder.getAddress([longitude, latitude], function(status, rs) {
rs = rs.regeocode || {};
parseResult(rs.formattedAddress, rs.addressComponent || {});
})
});
}
if(mUtil.checkEmpJsApi("getLocation")){//e9移动平台
mUtil.invokeEmApi("getLocation", {
//高德地图使用的是火星坐标
type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
transformLL(res.longitude, res.latitude);
}
});
}else if(mUtil.runtime.isEmobile6()){//em6
window.getLBSResult = function(result){
var arr = result.split(",");
var longitude = arr[2];
var latitude = arr[1];
transformLL(longitude, latitude);
};
location = "emobile:gps:getLBSResult";
}else if(typeof(eb_GetLocation) != "undefined" && mUtil.isFunction(eb_GetLocation)){//云桥
window.getLBSResult = function(longitude, latitude){
transformLL(longitude, latitude);
};
eb_GetLocation("getLBSResult");
}else{//浏览器
AMap.plugin('AMap.Geolocation', function() {
var geolocation = new AMap.Geolocation({
enableHighAccuracy: true//是否使用高精度定位,默认:true
});
geolocation.getCurrentPosition(function(status,result){
if(status === 'complete'){
transformLL(result.position.P, result.position.O);
}else{
mUtil.console.error(result.message);
}
});
});
}
}
};
});