mobilemode.api.lbs_wev8.js
2.11 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
define("mApi/lbs", ["mUtil", "baidumap"], function(mUtil) {
return {
getCurrentPosition: function(callback){
function transformLL(longitude, latitude){
var gdPoint = new BMap.Point(longitude, latitude);
var convertor = new BMap.Convertor();
convertor.translate([gdPoint], 3, 5, function(data){
var point = data.points[0];
var geoc = new BMap.Geocoder();
geoc.getLocation(point, function(rs){
var addComp = rs.addressComponents;
var addr = rs.address;
var result = {};
result["status"] = "1";
result["errMsg"] = ""; //错误信息
result["lng"] = point.lng; //经度
result["lat"] = point.lat; //纬度
result["addr"] = addr; //中文地址
result["province"] = addComp.province; //省份
result["city"] = addComp.city; //城市
result["district"] = addComp.district; //区
result["street"] = addComp.street; //街道
result["streetNumber"] = addComp.streetNumber; //街道号码
result["gd_lng"] = longitude; //高德/腾讯地图经度
result["gd_lat"] = latitude; //高德/腾讯地图纬度
callback && callback(result);
});
});
}
if(mUtil.checkEmpJsApi("getLocation")){
mUtil.invokeEmApi("getLocation", {
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
transformLL(res.longitude, res.latitude);
}
});
}else if(mUtil.runtime.isEmobile6()){
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");
}
}
};
});