1/** 2 * æµè§å¨å®ä½ 3 * 注ï¼pcä¸å®ä½ä¸åï¼è¯·å¨ææºæ¨¡å¼ä¸æµè¯ 4 * 5 * å¦åºç°ä½ç½®åå·®é®é¢ï¼ å¯åèwikiï¼http://wiki.we.com:8090/pages/viewpage.action?pageId=60819886 6 * 7 * @author imp.zhang 8 * @date 2020-03-11 9 * @version 1.0 10 */ 11 12var To8toGeo = function() { 13 14 var timeClock 15 var timeNum = 0 16 17 function timeClockFun () { 18 timeClock = setTimeout(function() { 19 timeNum ++ 20 timeClockFun() 21 }, 1000) 22 } 23 24 this.options = { 25 debug: false, // æ¯å¦å¼å¯debug æ¨¡å¼ 26 type: "default", // å®ä½æ¹å¼, default é»è®¤æµè§å¨èªå¸¦, baidu ç¾åº¦å®ä½ 27 assist: "", // å婿¹å¼ï¼defaultå®ä½æ¹å¼ä¸ï¼éç¨å ¶ä»å婿¹å¼ã eg: baidu 28 callback: function() {}, 29 errorCallback: function() {}, 30 31 baiduAk: "UrL3fRggHKhAzvXLoGjsGxrdBZ9vdom2", // ç¾åº¦å°å¾ak 32 33 // æµè§å¨å®ä½ç¸å ³é ç½® 34 enableHighAccuracy: true, 35 timeout: 8000, 36 maximumAge: 0, 37 }; 38 39 this.initialized = false; 40 this.province = ""; 41 this.city = ""; 42 this.town = ""; 43 this.street = ""; 44 this.longitude = ""; 45 this.latitude = ""; 46 this.baiduGeoloation = null; 47 48 this.to8toLocationApi = "https://www.to8to.com/api/landpage/app.php?m=location&a=geo"; 49 this.to8toRecordApi = "https://www.to8to.com/api/landpage/app.php?m=log&a=log"; 50 51 // åå§å 52 this.initialize = function(options) { 53 this.options = $.extend(this.options, options); 54 this.initialized = true; 55 56 this.initLocator(); 57 }; 58 59 // åå§åå®ä½å¨ 60 this.initLocator = function() { 61 switch (this.options.type) { 62 case 'baidu': 63 this.initBaiduLocator(); 64 break; 65 default: 66 this.initDefaultLocator(); 67 break; 68 } 69 }; 70 71 //è®°å½æ¥å¿ 72 this.recordLog = function(params){ 73 $.ajax({
74 type: "GET", 75 url: this.to8toRecordApi, 76 data: params, 77 success: function (res) { 78 79 }, 80 error: function (res) { 81 } 82 }); 83 } 84 85 // åå§åæµè§å¨èªå¸¦å®ä½ 86 this.initDefaultLocator = function() { 87 this.log("default location."); 88 var self = this; 89 var options = { 90 enableHighAccuracy: this.options.enableHighAccuracy, 91 timeout: this.options.timeout, 92 maximumAge: this.options.maximumAge, 93 }; 94 if (navigator.geolocation) { 95 timeClockFun() 96 navigator.geolocation.getCurrentPosition(function (position) { 97 clearTimeout(timeClock) 98 self.pushMessage() 99 self.log("default location success. x = " + position.coords.longitude + " y: " + position.coords.latitude + " position: " + JSON.stringify(position)); 100 self.longitude = position.coords.longitude; // ç»åº¦ 101 self.latitude = position.coords.latitude; // 纬度 102 self.to8toParseAddressByGEO(self.longitude, self.latitude, 'default'); 103 }, function () { 104 self.log("default location error."); 105 if (self.options.assist == 'baidu') { 106 self.initBaiduLocator(); 107 return; 108 } 109 110 self.locationError(); 111 }, options); 112 } else { 113 this.errorCallback(this); 114 // alert("æµè§å¨ä¸æ¯æå°çå®ä½ã"); 115 } 116 }; 117 118 119 // to8toæ ¹æ®ç»çº¬åº¦è½¬æ¢å°å 120 this.to8toParseAddressByGEO = function(lng, lat, type) { 121 var self = this; 122 $.ajax({
123 type: "GET", 124 url: this.to8toLocationApi, 125 dataType: "jsonp", 126 jsonpCallback: "jsonpCallback", 127 data: { 128 lng: lng, 129 lat: lat, 130 }, 131 success: function (res) { 132 self.log("to8to location res: ") 133 self.log(JSON.stringify(res)) 134 self.province = res.data.province; 135 self.city = res.data.city; 136 self.town = res.data.town; 137 self.street = res.data.street; 138 139 self.locationSuccess(self.getAddress()); 140 var recordInfo = { 141 location: type, 142 longitude: lng, 143 latitude: lat, 144 city: self.city, 145 town: self.town, 146 street: self.street, 147 province: self.province, 148 result: 'success', 149 }; 150 self.recordLog(recordInfo); 151 }, 152 error: function (res) { 153 var recordInfo = { 154 location: type, 155 result: 'fail', 156 }; 157 self.recordLog(recordInfo); 158 } 159 }); 160 }; 161 162 163 // ç¾åº¦å®ä½å¨ 164 this.initBaiduLocator = function () { 165 this.log("baidu location."); 166 var self = this; 167 this.baiduGeoloation = new BMap.Geolocation(); 168 this.baiduGeoloation.getCurrentPosition(function (r) { 169 if (this.getStatus() == BMAP_STATUS_SUCCESS) { 170 self.log('baidu locaiton success. x = ' + r.point.lng + ", " + " y: " + r.point.lat); 171 self.longitude = r.point.lng; 172 self.latitude = r.point.lat; 173 174 self.to8toParseAddressByGEO(self.longitude, self.latitude, 'baidu'); 175 176 // self.baiduParseAddressByGeo(r.point); 177 } 178 else { 179 self.log('baidu locaiton failed' + this.getStatus()); 180 self.locationError(); 181 } 182 }, {enableHighAccuracy: true}) 183 }; 184 185 186 // ç¾åº¦è¯¦ç»å®ä½ 187 this.baiduParseAddressByGeo = function(point) { 188 var self = this; 189 var gc = new BMap.Geocoder(); 190 gc.getLocation(point, function (rs) { 191 var addComp = rs.addressComponents; 192 self.province = addComp.province; 193 self.city = addComp.city; 194 self.town = addComp.district; 195 self.street = addComp.street + addComp.streetNumber; 196 197 self.locationSuccess(self.getAddress()); 198 }); 199 }; 200 201 // å®ä½å¤±è´¥åè° 202 this.locationError = function() { 203 var self = this; 204 this.errorCallback(self); 205 }; 206 207 // å®ä½æå 208 // @params getAddress() 209 this.locationSuccess = function(params) { 210 this.log("location success callback."); 211 if (typeof this.options.callback == 'function') { 212 this.options.callback(params); 213 } 214 }; 215 216 // æ¬æ¹æ³ä½ç¨ä¸åäºlocationError, ç¨äºå®ä½å¤±è´¥åè¡¥æå·¥ä½ 217 this.errorCallback = function (params) { 218 // æ·»å å®ä½å¤±è´¥æ¥å¿ä¸æ¥ 219 try { 220 this.recordLog({ 221 key: 'geolocation_error' 222 }) 223 } catch (error) { 224 225 } 226 this.log("location errorCallback."); 227 if (typeof this.options.errorCallback == 'function') { 228 this.options.errorCallback(params); 229 } 230 }; 231 232 // è·åå°å 233 this.getAddress = function() { 234 var address = { 235 province: this.province, 236 city: this.city, 237 town: this.town, 238 street: this.street, 239 longitude: this.longitude, 240 latitude: this.latitude, 241 } 242 return address; 243 }; 244 245 // 详ç»å°å 246 this.getDetailAddress = function() { 247 return this.province + this.city + this.town + this.street; 248 }; 249 250 // log 251 this.log = function(msg) { 252 if (this.options.debug && $("#debug").length == 0) { 253 var html = '<div id="debug" style=" width: 100%; background: #ccc; min-height: 50px; margin-top: 20px; line-height: 1.4; padding: 10px; font-size: 18px; border: 3px dashed #62625e;"><B>debug</B><Br></div>'; 254 $("body").append(html) 255 } 256 257 if (this.options.debug) { 258 $("#debug").append(msg + "<br/>"); 259 } 260 261 // console.log(msg) 262 } 263 264 // 忥å£ä¸æ¥å 容 265 this.pushMessage = function() { 266 $.ajax({
267 url: 'https://www.to8to.com/api/landpage/app.php', 268 type: 'get', 269 data: { 270 m: 'log', 271 a: 'log', 272 source: 'geolocation', 273 time: timeNum 274 }, 275 dataType: 'json', 276 success: function() {} 277 }) 278 } 279 280}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.