////////////////////////////////////////////////////////////////////////// //宏定义 cc.Class({ extends: cc.GameView, properties: { //m_btGPS:cc.Node, m_ActionPrefab: cc.Prefab, m_CardViewPrefab: cc.Prefab, //m_btChat: cc.Node, m_lLeftCardCount: cc.Label, // m_LeftCard:cc.Sprite, m_btOpation: cc.Button, m_Piao: cc.Node, m_BtXia1: cc.Toggle, m_BtXia2: cc.Node, m_BtXia5: cc.Node, m_MagicCtrl: cc.Node, m_Trustee: cc.Node, // m_LabHuangZhuang:cc.Label, // m_BirdNode:cc.Node, // m_BirdCard:[cc.Node], // m_CardFrame:[cc.SpriteFrame], m_RulesText: cc.Label, m_subsumlun: cc.Label, m_TableNumber: cc.Label, m_TableName: cc.Label, m_ClubNum: cc.Label, m_Dice: [cc.Node], m_Fengju: cc.Label, m_Rolldice: cc.Prefab, m_NewRolldice: cc.Node, m_noticeNode: cc.Node, m_gotFlowersNode: cc.Node, }, ctor: function () { this.m_ActionArray = new Array(); this.m_UserPosArr = new Array( cc.v2(575, 255), cc.v2(-580, 50), cc.v2(-580, -140), cc.v2(575, 50) ); this.m_UserFaceArr = this.m_UserPosArr; // this.m_UserVoiceArr = new Array( // cc.v2(-262, 255), // cc.v2(-508, 50), // cc.v2(-508, -140), // cc.v2(500, 75) // ); this.m_UserVoiceArr = this.m_UserFaceArr; this.m_UserChatArr = this.m_UserVoiceArr; this.m_ActionPos = new Array( cc.v2(0, 180), cc.v2(-380, 95), cc.v2(0, -160), cc.v2(380, 30) ); this.m_UserInfo = new Array(); //用户信息 this.m_pIClientUserItem = new Array(); this.m_WeaveCard = new Array(); //组合扑克 this.m_bTrustee = new Array(); this.m_bLeave = new Array(); //是否离开 this.m_UserCnt = 4; this.m_bInit = false; this.m_strCheckIP = new Array(4); this.m_strCheckDistance = new Array(6); for (var i = 0; i < 4; i++) { this.m_strCheckIP[i] = new Array(3);// 0:id 1:昵称 2:ip } this.m_noticeArr = []; }, start: function () { this.InitView(); this.Init(); }, Init: function () { if (this.m_bInit == true) return; this.m_bInit = true; this.ResetData(); //玩家头像信息 for (var i = 0; i < GameDef.GAME_PLAYER; i++) { this.m_UserInfo[i] = cc.instantiate(this.m_UserPrefab); this.m_UserNode.addChild(this.m_UserInfo[i]); this.m_UserInfo[i] = this.m_UserInfo[i].getComponent('UserPrefab_' + GameDef.KIND_ID); this.m_UserInfo[i].Init(this, i); this.m_UserInfo[i].node.active = false; } this.m_MagicCtrl = this.m_MagicCtrl.getComponent('HunPaiCtrl_' + GameDef.KIND_ID); this.m_MagicCtrl.SetEngine(this.m_GameClientEngine); this.m_CardView = cc.instantiate(this.m_CardViewPrefab).getComponent('CardView'); this.m_CardNode.addChild(this.m_CardView.node); this.m_CardView.setClickSendCard(false); this.RectifyControl(window.SCENE_WIGHT, window.SCENE_HEIGHT); this.ShowPrefabDLG('MacInfo', this.m_NdPhoneNode); this.m_PiaoScore = 0; this.m_Trustee.active = false; this.m_RulesText.string = ""; this.m_subsumlun.string = this.m_LbGameProgress.string; this.m_ClubNum.string = ""; this.m_Fengju.string = ""; this.m_TableNumber.string = this.m_LbTableID.string; }, updateGameRule() { console.log("游戏规则-", GameDef.m_dwGameRuleArr) if (GameDef.m_dwGameRuleArr[3] > 0) { this.m_TableNumber.node.active = false; this.m_TableName.node.active = true; this.m_TableName.node.string = GameDef.getGameFieldName(); } else { this.m_TableName.node.active = false; this.m_TableNumber.node.active = true; } }, Fengju: function (cbQuan, cbFeng, display) { var directions = ["東", "南", "西", "北"]; let cbQuanStr = directions[cbQuan]; let cbFengStr = directions[cbFeng]; this.m_Fengju.string = cbQuanStr + "風" + cbFengStr + "局"; if (!display) { this.m_Fengju.string = ""; } }, DiceNum: function (dice) { this.ShowDice(true); for (var i = 0; i < this.m_Dice.length; i++) { for (var j = 0; j < this.m_Dice[i].children.length; j++) { if (dice[i] == j + 1) { this.m_Dice[i].children[j].active = true; } else { this.m_Dice[i].children[j].active = false; } } } console.log("骰子数", dice) }, //隐藏显示骰子 ShowDice: function (bShow) { for (var i = 0; i < this.m_Dice.length; i++) { this.m_Dice[i].active = bShow; } }, //摇骰子 OnRollDice: function (dice) { let newRolldiceInstance = cc.instantiate(this.m_Rolldice); this.m_NewRolldice.addChild(newRolldiceInstance); this.m_NewRolldice.active = true; newRolldiceInstance.getComponent("Rolldice").rollDice(dice); this.scheduleOnce(() => { this.m_NewRolldice.active = false; newRolldiceInstance.destroy(); }, 2); }, ChangeCardBack: function (Index) { // this.m_LeftCard.spriteFrame = this.m_CardFrame[Index]; }, ResetData: function () { //this.m_Piao.active = false; this.SetGangOperator(0); for (var i = 0; i < GameDef.GAME_PLAYER; ++i) { this.m_pIClientUserItem[i] = null; this.m_WeaveCard[i] = new Array(GameDef.MAX_WEAVE); this.m_bTrustee[i] = false; this.m_bLeave[i] = false; } this.m_wOutCardUser = INVALID_CHAIR; this.m_cbLeftCardCount = 0; this.m_lLeftCardCount.string = ''; }, //用户信息更新 OnUserEnter: function (pUserItem, wChairID) { this.Init(); this.m_pIClientUserItem[wChairID] = pUserItem; this.m_UserInfo[wChairID].SetUserItem(pUserItem); this.m_UserInfo[wChairID].node.active = true; if (pUserItem.GetUserStatus() == US_READY) this.m_UserInfo[wChairID].SetReady(pUserItem); var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData(); if (pGlobalUserData.dwUserID != pUserItem.GetUserID()) return; if (this.m_GameClientEngine.IsLookonMode() == false) { //邀请第三方好友暂未开放,先隐藏按钮 // this.m_BtFriend.active = (this.m_GameClientEngine.m_dwRoomID != 0 && this.m_GameClientEngine.m_wGameProgress == 0); this.m_BtFriend.active = false; this.m_BtStart.active = pUserItem.GetUserStatus() == US_SIT; } //if(pUserItem.GetUserStatus() == US_READY) this.SetUserState(wChairID, 'Ready'); //this.m_UserInfo[wChairID].SetOffLine(pUserItem.GetUserStatus() == US_OFFLINE) //this.scheduleOnce(function(){this.UpdateGPS();}, 5); // this.CheckIP(); if (wChairID == GameDef.MYSELF_VIEW_ID) { if (this.m_ChatControl == null) { this.ShowPrefabDLG('ChatPrefab', this.node, function (Js) { this.m_ChatControl = Js; this.m_ChatControl.ShowSendChat(false); this.m_ChatControl.InitHook(this); }.bind(this)); } if (this.m_VoiceCtrl == null) { this.ShowPrefabDLG('VoiceCtrl', this.node.getChildByName('VoiceNode'), function (Js) { this.m_VoiceCtrl = Js; this.m_VoiceCtrl.InitVoice(this); var NdButton = this.m_VoiceCtrl.node.getChildByName('Voice').getChildByName('btVoice'); NdButton.setPosition(570, -170); }.bind(this)); } if (this.m_FaceExCtrl == null) { this.ShowPrefabDLG('FaceExCtrl', this.m_AniNode, function (Js) { this.m_FaceExCtrl = Js; }.bind(this)); } //this.m_BtStart.active = !(this.m_GameClientEngine.IsLookonMode() || US_READY == pUserItem.GetUserStatus() || US_PLAYING == pUserItem.GetUserStatus()); } }, OnUserState: function (pUserItem, wChairID) { this.Init(); this.m_pIClientUserItem[wChairID] = pUserItem; this.m_UserInfo[wChairID].OnUserOffLine(pUserItem.GetUserStatus() == US_OFFLINE); this.m_UserInfo[wChairID].SetReady(false); if (pUserItem.GetUserStatus() == US_READY) { this.m_UserInfo[wChairID].SetReady(true); this.m_GameClientEngine.PlayActionSound(pUserItem.GetChairID(), "ZHUNBEI"); if (GameDef.MYSELF_VIEW_ID == wChairID) this.m_BtStart.active = false; } }, OnUserLeave: function (pUserItem, wChairID) { this.Init(); var ViewID = this.m_GameClientEngine.SwitchViewChairID(wChairID); for (var i in this.m_UserInfo) { this.m_UserInfo[i].UserLeave(pUserItem); } this.m_pIClientUserItem[wChairID] = null; }, OnUserScore: function (pUserItem, wChairID) { // 初始化当前对象的状态 this.Init(); // 将用户项对象赋值给指定椅子ID的客户端用户项数组 this.m_pIClientUserItem[wChairID] = pUserItem; // 更新指定椅子ID的用户信息对象中的分数 this.m_UserInfo[wChairID].UpdateScore(pUserItem); }, onLoadOthers: function () { }, //调整控件 RectifyControl: function (nWidth, nHeight) { //玩家信息 for (var i = 0; i < GameDef.GAME_PLAYER; i++) { this.m_UserInfo[i].SetBenchmarkPos(this.m_UserPosArr[i]); } }, OnBnClickedResultFriend: function () { cc.gSoundRes.PlaySound("Button"); this.m_GameClientEngine.OnResultFriend(); }, OnBnClickedFriendBg: function () { this.m_WXShare.SetShowType(false); }, OnBnClickedNextReady: function () { cc.gSoundRes.PlaySound("Button"); this.m_GameClientEngine.OnNextReady(); }, OnBnClickedFollow: function () { this.m_GameClientEngine.OnFollow(0, 0); }, OnBnClickedNoAdd: function () { this.m_GameClientEngine.OnFollow(1, 0); }, OnBnClickedGiveUp: function () { this.m_GameClientEngine.OnGiveUp(); }, OnBnClickedFourTimes: function () { this.m_GameClientEngine.OnAddScore(1, 0); }, OnBnClickedEightTimes: function () { this.m_GameClientEngine.OnAddScore(2, 0); }, OnBnClickedSixteenTimes: function () { this.m_GameClientEngine.OnAddScore(3, 0); }, OnExitGameCallback: function () { if (cc.sys.OS_IOS == cc.sys.os) { jsb.reflection.callStaticMethod("AppActivity", "exitGame"); } else { jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "exitGame", "()V"); } }, //取消托管 OnBtCancelTrustee: function () { cc.gSoundRes.PlaySound("Button"); this.m_GameClientEngine.OnCancelTrustee(false); }, //设置托管 SetTrustee: function (wTrusteeUser, bTrustee) { if (this.m_GameClientEngine.m_ReplayMode) return; //设置数据 this.m_bTrustee[wTrusteeUser] = bTrustee; var wMeChairID = this.m_GameClientEngine.GetMeChairID(); var ViewID = this.m_GameClientEngine.SwitchViewChairID(wTrusteeUser); this.m_UserInfo[ViewID].SetTrustee(bTrustee); if (wMeChairID == wTrusteeUser) { this.m_Trustee.active = bTrustee; } }, SetBankerUser: function (wBankerUser) { //设置用户 if (wBankerUser != this.m_wBankerUser) { //设置变量 this.m_wBankerUser = wBankerUser; for (var i = 0; i < GameDef.GAME_PLAYER; i++) { if (this.m_UserInfo[i].node.active) this.m_UserInfo[i].SetBanker(i == wBankerUser); } } }, SetCurrentUser(wCurrentUser) { var ViewID = this.m_GameClientEngine.SwitchViewChairID(wCurrentUser); for (let i = 0; i < GameDef.GAME_PLAYER; i++) { this.m_UserInfo[i].SetPlaying(ViewID == i); } this.m_CardView.SetCurrentUser(wCurrentUser); }, //动作信息 SetUserAction: function (wViewChairID, bUserAction, zimo) { //回放回滚 if (this.m_GameClientEngine.m_bRollBack) return; // //设置变量 if (wViewChairID < GameDef.GAME_PLAYER) { if (this.m_ActionArray[wViewChairID] == null) { var ActionPrefab = cc.instantiate(this.m_ActionPrefab); var ActionNode = ActionPrefab.getComponent('ActionCtrl_' + GameDef.KIND_ID); this.m_AniNode.addChild(ActionPrefab); ActionPrefab.setPosition(this.m_ActionPos[wViewChairID]); this.m_ActionArray[wViewChairID] = ActionNode; } this.m_ActionArray[wViewChairID].SetAction(bUserAction, zimo); } }, //出牌信息 SetOutCardInfo: function (wViewChairID, cbCardData) { }, //设置剩余 SetLeftCardCount: function (cbLeftCardCount) { if (this.m_cbLeftCardCount != cbLeftCardCount || cbLeftCardCount == 0) { this.m_cbLeftCardCount = cbLeftCardCount; this.m_lLeftCardCount.string = cbLeftCardCount.toString(); } return; }, //基础积分 SetCellScore: function (lCellScore) { return; }, //设置时间 SetUserTimer: function (wChairID, wTimer) { var cbNum = this.m_CardView.m_CenterViewCtrl.setTimerNum(true/*wChairID!=INVALID_CHAIR*/, wTimer); return true; }, // SetScoreInfo:function(wViewID,lScore){ // this.m_UserInfo[wViewID].SetUserScore(lScore); // }, SetPlayStatus: function (wChairID, cbStatus) { }, //设置离开 SetLeave: function (wLeaveUser, bLeave) { //校验数据 if (wLeaveUser < 0 && wLeaveUser >= GameDef.GAME_PLAYER) { console.log("SetTrustee error 1 wLeaveUser < 0 && wLeaveUser >= GameDef.GAME_PLAYER"); } if (this.m_bLeave[wLeaveUser] != bLeave) { //设置数据 this.m_bLeave[wLeaveUser] = bLeave; this.m_UserInfo[wLeaveUser].SetLeave(bLeave); } }, SetViewRoomInfo: function (dwRulesArr, dwServerRules) { // this.UpdateClubID(); //this.m_LbGameRules.string = GameDef.GetRulesStr(dwRulesArr, dwServerRules); this.m_RulesText.string = GameDef.GetRulesStr(dwServerRules, dwRulesArr); this.m_LbTableID.string = '' + this.m_GameClientEngine.m_dwRoomID; //if(this.m_btGPS != null) this.m_btGPS.active = GameDef.IsNoCheat(dwServerRules); var bShow = this.m_GameClientEngine.IsLookonMode(); if (this.m_BtChat) this.m_BtChat.active = !bShow; //GBS功能暂停,暂时隐藏 //if (this.m_BtGPS) this.m_BtGPS.active = !bShow; if (this.m_BtMenu) this.m_BtMenu.active = !bShow; this.m_MagicCtrl.node.active = false; }, UpdateRoomProgress: function () { this.m_LbGameProgress.string = '圈數:' + GameDef.GetProgress(this.m_GameClientEngine.m_wGameProgress, this.m_GameClientEngine.m_dwServerRules); }, // 0:隐藏所有 1:显示按钮 2:显示等待 SetGangOperator: function (wValue) { if (wValue == 1) { this.m_Piao.active = true; this.m_BtXia1.check(); this.m_PiaoScore = 1 if (this.m_GameClientEngine.m_dwRulesArr[0] & GameDef.GAME_RULE_SP_3)//飘123 { this.m_BtXia2.active = true; this.m_BtXia5.active = false; } else if (this.m_GameClientEngine.m_dwRulesArr[0] & GameDef.GAME_RULE_SP_5)//飘135 { this.m_BtXia2.active = false; this.m_BtXia5.active = true; } } else { this.m_Piao.active = false; } }, OnBtPiao: function (tag, data) { this.m_PiaoScore = parseInt(data); }, OnBtEnterPiao: function () { cc.gSoundRes.PlaySound("Button"); this.m_GameClientEngine.OnDoubleOperate(this.m_PiaoScore); this.SetGangOperator(2); }, // OnBtShowGPS:function(){ // if(this.m_GameClientEngine.m_dwRoomID == 0) return; // this.ShowGamePrefab('TableUserGPS', GameDef.KIND_ID,this.node, function(Js){ // this.m_TableGPSCtrl = Js; // this.m_TableGPSCtrl.Init(); // this.m_TableGPSCtrl.UpdateUserData(); // this.m_GameClientEngine.GetTableUserGPS(); // }.bind(this)); // }, // OnGPSAddress:function(GPSInfo){ // this.CheckDistance(GPSInfo); // if(this.m_TableGPSCtrl) // { // for(var i = 0; i < GameDef.GAME_PLAYER; i++) // { // if(this.m_pIClientUserItem[i] != null) // { // this.m_TableGPSCtrl.SetUserAddress(this.m_pIClientUserItem[i]); // } // } // this.m_TableGPSCtrl.UpdateAddress(GPSInfo); // } // }, SetMakeMagicIndex: function (index) { if (this.m_MagicCtrl.node.active) { this.m_MagicCtrl.SetMakeMagicIndex(index); } }, SetHuiPai: function (DingHui, CardData) { if (this.m_MagicCtrl.node.active) { this.m_MagicCtrl.SetHuiPai(DingHui, CardData); } }, ShockHuiPai: function () { if (this.m_MagicCtrl.node.active) { this.m_MagicCtrl.ShockHuiPai(); } }, SetCurrentAction: function (viewID) { for (let i = 0; i < GameDef.GAME_PLAYER; i++) { if (this.m_UserInfo[i] != null) { this.m_UserInfo[i].SetCurrentAction(i == viewID); } } }, // ShowBird:function(BirdCard, BirdCardCount) // { // var Self = this; // Self.scheduleOnce(function() // { // Self.m_BirdNode.active = true; // var BirdCardItem = new Array(); // for(var i = 0; i < Self.m_BirdCard.length; i++) // { // Self.m_BirdCard[i].active = i < BirdCardCount; // if(i < BirdCardCount) // { // BirdCardItem[i] = Self.m_BirdCard[i].getComponent("CardItem"); // BirdCardItem[i].SetCardData(BirdCard[i]); // } // } // Self.scheduleOnce(function(){ Self.m_BirdNode.active = false; }.bind(this), 2); // }.bind(this), 1); // }, updateUserCount: function () { return; var UserCount = GameDef.GetPlayerCount(); if (UserCount == 2) { this.m_UserInfo[0].node.active = true; this.m_UserInfo[2].node.active = true; this.m_UserInfo[1].node.active = false; this.m_UserInfo[3].node.active = false; } else { for (var i = 0; i < GameDef.GAME_PLAYER; i++) { var wViewID = this.m_GameClientEngine.SwitchViewChairID(i); this.m_UserInfo[wViewID].node.active = i < UserCount; } } // this.m_TableGPSCtrl.SetUserCount(UserCount); }, //黄庄次数 // SetHuangZhuang:function(wCount) // { // this.m_LabHuangZhuang.string = wCount; // }, //更新gps UpdateGPS: function () { this.m_GameClientEngine.GetTableUserGPS(); }, onGameBroadcast(noticeStr) { if (!!noticeStr == false/* || noticeStr.length <= 0 */) { return; } if (false == !!this.m_noticeNode) { return; } let showNoticeCb = () => { if (0 == this.m_noticeArr.length) { this._showBroadcast(noticeStr); } else { this.m_noticeArr.push(noticeStr); } }; if (!this.m_noticeNode.active) { this.m_noticeNode.active = true; this.m_noticeNode.opacity = 0; cc.tween(this.m_noticeNode) .to(0.25, { opacity: 255 }) .call(() => { showNoticeCb(); }) .start(); } else { showNoticeCb(); } }, //游戏跑马灯 _showBroadcast(str) { let noticeNode = this.m_noticeLab.node; noticeNode.stopAllActions(); if (!!str == false || str.length <= 0) { return; } let newShowCb = () => { if (this.m_noticeArr.length <= 0) { cc.tween(this.m_noticeNode) .to(0.25, { opacity: 0 }) .call(() => { this.m_noticeNode.active = false; this.m_noticeNode.opacity = 255; }) .start(); return; } this._showBroadcast(this.m_noticeArr.shift()); }; this.m_noticeLab.string = str; let startX = noticeNode.parent.width / 2 + 20; noticeNode.x = startX; this.scheduleOnce(() => { let endX = -startX - noticeNode.width; let moveTime = (noticeNode.parent.width + noticeNode.width) / 20; cc.tween(noticeNode) .to(moveTime, { x: endX }) .call(newShowCb) .start(); }, 0.25); }, //展示补花 showGotFlowers(viewID, isShow) { if (isNaN(viewID)) { return; } let showNode = this.m_gotFlowersNode.children[viewID]; if (false == !!showNode) { return; } showNode.active = !!isShow; if (!isShow) { return; } showNode.getComponent("SpineAnimationCtrl").playAnimation(); }, //#region 工具函数 //检测同ip CheckIP: function () { for (var i = 0; i < GameDef.GAME_PLAYER; i++) { this.m_strCheckIP[i] = new Array(3);// 0:id 1:昵称 2:ip this.m_strCheckIP[i][0] = 0; } var nIndex = 0; for (var i = 0; i < GameDef.GAME_PLAYER; i++) { if (this.m_pIClientUserItem[i] != null) { for (var j = i + 1; j < GameDef.GAME_PLAYER; j++) { if (this.m_pIClientUserItem[j] != null) { if (this.m_pIClientUserItem[i].GetUserIP() == this.m_pIClientUserItem[j].GetUserIP()) { //排重 var bIHas = false; var bJHas = false; for (var k = 0; k < GameDef.GAME_PLAYER; k++) { if (this.m_strCheckIP[k][0] == 0) break; if (this.m_pIClientUserItem[i].GetUserID() == this.m_strCheckIP[k][0]) { bIHas = true; } if (this.m_pIClientUserItem[j].GetUserID() == this.m_strCheckIP[k][0]) { bJHas = true; } } if (bIHas == false) { this.m_strCheckIP[nIndex][0] = this.m_pIClientUserItem[i].GetUserID(); this.m_strCheckIP[nIndex][1] = this.m_pIClientUserItem[i].GetNickName(); this.m_strCheckIP[nIndex][2] = this.m_pIClientUserItem[i].GetUserIP(); nIndex++; } if (bJHas == false) { this.m_strCheckIP[nIndex][0] = this.m_pIClientUserItem[j].GetUserID(); this.m_strCheckIP[nIndex][1] = this.m_pIClientUserItem[j].GetNickName(); this.m_strCheckIP[nIndex][2] = this.m_pIClientUserItem[j].GetUserIP(); nIndex++; } } } } } } }, //检测距离过近 CheckDistance: function (GPSInfo) { for (var i = 0; i < 6; i++) { this.m_strCheckDistance[i] = null; } var nIndex = 0; for (var i = 0; i < GameDef.GAME_PLAYER; i++) { if (GPSInfo[i] == null) continue; for (var j = i + 1; j < GameDef.GAME_PLAYER; j++) { if (GPSInfo[j] == null) continue; if (0 != GPSInfo[i].dlongitude && 0 != GPSInfo[j].dlongitude) { var dis = this.GetDistance(GPSInfo[i].dlatitude, GPSInfo[i].dlongitude, GPSInfo[j].dlatitude, GPSInfo[j].dlongitude); if (dis < 0.05)//50米内 { var tmpName = new Array(2); var tmpIndex = 0; for (var k = 0; k < GameDef.GAME_PLAYER; k++) { if (this.m_pIClientUserItem[k] != null) { var timUserID = this.m_pIClientUserItem[k].GetUserID(); if (timUserID == GPSInfo[i].dwUserID || timUserID == GPSInfo[j].dwUserID) { tmpName[tmpIndex] = this.m_pIClientUserItem[k].GetNickName(); tmpIndex++; } } } this.m_strCheckDistance[nIndex] = tmpName[0] + ' 与 ' + tmpName[1] + ' 距离过近!' nIndex++; } } } } }, //计算距离,参数分别为第一点的纬度,经度;第二点的纬度,经度 GetDistance: function (lat1, lng1, lat2, lng2) { var radLat1 = this._Rad(lat1); var radLat2 = this._Rad(lat2); var a = radLat1 - radLat2; var b = this._Rad(lng1) - this._Rad(lng2); var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * 6378.137;// EARTH_RADIUS; s = Math.round(s * 10000) / 10000; //输出为公里 return s; }, _Rad: function (d) { return d * Math.PI / 180.0;//经纬度转换成三角函数中度分表形式。 }, });