E9定位重写

工作日志–定位重写E9

em.getLocation({
    locationType: '', 
    timeout: 2, 
    success: function (res) {
    	alert(JSON.stringify(res))
    },
    fail: function (res) {
        alert(JSON.stringify(res)); 
    }
});

地图api

//高德api
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.15&key=4cb2435c46a93df6cca74737a1d5d269&plugin=AMap.Geocoder"></script>

//百度api
<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=2.0&ak=3c7ce3d96104cca8edbf4f7ec3758ae2"></script>

重写方法

<script>
define("mApi/lbs4amap", ["mUtil", "amap"], function(mUtil) {    
var callbackStack = [];
// 	require(["mUtil"],function(mUtil){
	   return {
		getCurrPosition: function(callback, type){
		  //  alert(1);
			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移动平台
		    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);
                    }
                });
            });
        }else if(mUtil.runtime.isEmobile6()){//em6
        // alert(3);
    		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)){//云桥
    // 		alert(4);
    		window.getLBSResult = function(longitude, latitude){
    			transformLL(longitude, latitude);
    		};
    		eb_GetLocation("getLBSResult");
    	}else{//浏览器
    // 	alert(5);
    	    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);
                    }
                });
            });
    	}
    }
}; 
    // 	});
	
});
</script>

双重验证

top.window._p_wx_getLBSResult = function (longitude, latitude) {
		
		var map = new BMap.Map("allmap");
		var point = new BMap.Point(longitude,latitude);
		var convertor = new BMap.Convertor();
		var geoc = new BMap.Geocoder();
		geoc.getLocation(point, function(rs){
			//百度api解析
			var addr = rs.address;
			if(addr){
				//alert("111"+addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
				var result2 = {};
				result2["status"] = "1";
				result2["errMsg"] = "";	//错误信息
				result2["lng"] = point.lng;	//精度
				result2["lat"] = point.lat;	//纬度
				result2["addr"] = addr;	//中文地址
				alert(JSON.stringify(result2));
				cbFunction(result2);
			}else{
				//高德api解析
				AMap.plugin('AMap.Geocoder', function() {
				var geocoder = new AMap.Geocoder({
						radius: 1000, //范围,默认:500
						extensions:'base'
					});
					//地理编码,返回地理编码结果
					var lnglat = [point.lng,point.lat];
					geocoder.getAddress(lnglat , function(status, result) {
						if (status === 'complete' && result.info === 'OK') {
							result = result.regeocode.addressComponent;
							var addr = result.province + result.city + result.district + result.street + result.streetNumber;
							var result2 = {};
							result2["status"] = "1";
							result2["errMsg"] = "";	//错误信息
							result2["lng"] = point.lng;	//精度
							result2["lat"] = point.lat;	//纬度
							result2["addr"] = addr;	//中文地址
							result2["province"] = result.province;	//省份
							result2["city"] = result.city;	//城市
							result2["district"] = result.district;	//区
							result2["street"] = result.street;	//街道
							result2["streetNumber"] = result.streetNumber;	//街道号码
							cbFunction(result2);
						}else{
							alert("高德api百度api都解析失败!请联系管理员!");
						}
					});
				});
			}
			
		});	
	};
	```
	
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值