提交 3ae6bf90 编写于 作者: YYYTDMS's avatar YYYTDMS

330_图表bug和定位bug

上级 95804421
......@@ -4,6 +4,7 @@ import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import cn.qiuxiang.react.geolocation.AMapGeolocationPackage;
import com.th3rdwave.safeareacontext.SafeAreaContextPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.oblador.vectoricons.VectorIconsPackage;
......
rootProject.name = 'FZUStudyRoom'
include ':react-native-amap-geolocation'
project(':react-native-amap-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-amap-geolocation/lib/android')
include ':react-native-safe-area-context'
project(':react-native-safe-area-context').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-safe-area-context/android')
include ':react-native-vector-icons'
......
......@@ -61,6 +61,32 @@ class SchoolMapHome extends Component {
peoplenumw3: null,
peoplenumw4: null,
dateload: false,
leftsections: [
'第1节',
'第2节',
'第3节',
'第4节',
'第5节',
'第6节',
'第7节',
'第8节',
'第9节',
'第10节',
'第11节',
],
rightsections: [
'第1节',
'第2节',
'第3节',
'第4节',
'第5节',
'第6节',
'第7节',
'第8节',
'第9节',
'第10节',
'第11节',
],
};
this.querySingleRoom = this.querySingleRoom.bind(this);
this.query = this.query.bind(this);
......@@ -415,19 +441,32 @@ class SchoolMapHome extends Component {
_selectstart = (index, value) => {
console.log(index + '--' + value);
this.setState({
start: index,
dateload: false,
});
this.refreshRoomList();
var list = [];
for (let i = index; i < this.state.leftsections.length; i++) {
list.push(this.state.leftsections[i]);
}
this.setState(
{
start: index + 1,
dateload: false,
rightsections: list,
},
() => {
this.refreshRoomList();
},
);
};
_selectend = (index, value) => {
console.log(index + '--' + value);
this.setState({
end: index,
dateload: false,
});
this.refreshRoomList();
this.setState(
{
end: index + 1,
dateload: false,
},
() => {
this.refreshRoomList();
},
);
};
getTodayDate = () => {
const date = new Date();
......@@ -586,19 +625,7 @@ class SchoolMapHome extends Component {
this.setState({isIcon1: true});
}}
onSelect={this._selectstart} //当选项行与选定的index 和 value 接触时触发
options={[
'第1节',
'第2节',
'第3节',
'第4节',
'第5节',
'第6节',
'第7节',
'第8节',
'第9节',
'第10节',
'第11节',
]}
options={this.state.leftsections}
defaultValue="第1节"
/>
<Text
......@@ -635,19 +662,7 @@ class SchoolMapHome extends Component {
this.setState({isIcon2: true});
}}
onSelect={this._selectend} //当选项行与选定的index 和 value 接触时触发
options={[
'第1节',
'第2节',
'第3节',
'第4节',
'第5节',
'第6节',
'第7节',
'第8节',
'第9节',
'第10节',
'第11节',
]}
options={this.state.rightsections}
defaultValue="第11节"
/>
</View>
......
......@@ -153,13 +153,13 @@ class Analysis extends Component {
onlineDailyList[j]=0;
}
else{
onlineDailyList[j]=parseInt(onlineDailyRecord[days[j]])+(parseInt((onlineDailyRecord[days[j]]+0.05)*10)%10)*0.1;
onlineDailyList[j]=(parseInt(onlineDailyRecord[days[j]])+(parseInt((onlineDailyRecord[days[j]]+0.05)*10)%10)*0.1).toFixed(3);
}
if(aloneDailyRecord[days[j]]===undefined){
aloneDailyList[j]=0;
}
else{
aloneDailyList[j]=parseInt(aloneDailyRecord[days[j]])+(parseInt((aloneDailyRecord[days[j]]+0.05)*10)%10)*0.1;
aloneDailyList[j]=(parseInt(aloneDailyRecord[days[j]])+(parseInt((aloneDailyRecord[days[j]]+0.05)*10)%10)*0.1).toFixed(3);
}
}
console.log(onlineDailyRecord)
......
......@@ -17,27 +17,29 @@ class TwoPlayerPKHome extends Component {
super();
}
componentDidMount() {
if (Platform.OS === 'android') {
BackHandler.addEventListener('hardwareBackPress', this.backEvent);
}
}
// componentDidMount() {
// if (Platform.OS === 'android') {
// BackHandler.addEventListener('hardwareBackPress', this.backEvent);
// }
// }
componentWillUnmount() {
if (Platform.OS === 'android') {
BackHandler.removeEventListener('hardwareBackPress', this.backEvent);
}
// if (Platform.OS === 'android') {
// BackHandler.removeEventListener('hardwareBackPress', this.backEvent);
// }
// 卸载异步操作设置状态
this.setState = (state, callback) => {
return;
};
}
backEvent = () => {
this.props.navigation.goBack();
this.cancelSearching();
websocket.disconnect();
};
}
// backEvent = () => {
// this.props.navigation.goBack();
// this.cancelSearching();
// websocket.disconnect();
// };
state = {isStarted: false, isCanceling: false};
......
......@@ -8,7 +8,7 @@ import {Component} from "react";
* class sno 的 get() 和 set() 需要修改以指向“全局变量”中的“学号”
*/
const EARTH_RADIUS = 6371393; // metre
const DEFAULT_DISTANCE = 200; // metre
const DEFAULT_DISTANCE = 100; // metre
const URL_SHORT = 'http://www.tdms.xyz:8000/FZUStudy';
const URL_AREA_GET_ID = 'http://www.tdms.xyz:8000/FZUStudy/study/areaGetID';
const URL_AREA_MATCH = 'http://www.tdms.xyz:8000/FZUStudy/study/areamatch';
......@@ -375,7 +375,7 @@ function getDistance(longitude1, latitude1, longitude2, latitude2) {
}
function parseLocation(longitude, latitude) {
console.log('longitude: ' + longitude + ' latitude: ' + latitude);
// console.log('longitude: ' + longitude + ' latitude: ' + latitude);
let range = {
ID: 'notInRange',
distance: DEFAULT_DISTANCE,
......
import React, {Component} from 'react';
import {
View,
Text,
StyleSheet,
Dimensions,
Image,
ToastAndroid,
PermissionsAndroid,
Platform,
View,
Text,
StyleSheet,
Dimensions,
Image,
ToastAndroid,
PermissionsAndroid,
Platform,
} from 'react-native';
import Located from './img/located1.png';
import Locating from './img/locating1.png';
import MyButton from '../MyButton';
import Geolocation from '@react-native-community/geolocation';
import {parseRangeID, isLegalRangeID, acID, rangeID} from '../MyUtilities';
import {GPS} from "../../../utils/GPSTrans";
const {height} = Dimensions.get('window');
const config = {
skipPermissionRequests: false,
authorizationLevel: 'auto',
skipPermissionRequests: false,
authorizationLevel: 'auto',
};
Geolocation.setRNConfiguration(config);
class RangePKHome extends Component {
constructor() {
super();
}
componentDidMount() {
rangeID.set();
acID.set();
}
componentWillUnmount() {
// this.cancelLocating();
// 卸载异步操作设置状态
this.setState = (state, callback) => {
return;
constructor() {
super();
}
componentDidMount() {
rangeID.set();
acID.set();
}
componentWillUnmount() {
// this.cancelLocating();
// 卸载异步操作设置状态
this.setState = (state, callback) => {
return;
};
rangeID.set();
acID.set();
}
state = {
isStarted: false,
isLocated: false,
longitude: undefined,
latitude: undefined,
};
rangeID.set();
acID.set();
}
state = {
isStarted: false,
isLocated: false,
longitude: undefined,
latitude: undefined,
};
// abortController = null;
getPositions = () => {
//获取位置再得到城市先后顺序,通过Promise完成
return new Promise((resolve, reject) => {
// this.abortController.signal.addEventListener('abort', () => {
// const error = {code: 100, message: 'Locating request is aborted.'};
// return reject(error);
// });
Geolocation.getCurrentPosition(
location => {
const longitude = location.coords.longitude; //经度
const latitude = location.coords.latitude; //纬度
// console.log('longitude:',longitude)
// console.log('latitude:',latitude)
rangeID.setByLocation(longitude, latitude);
this.setState({
isStarted: false,
isLocated: true,
});
},
error => {
reject(error);
this.setState({isStarted: false});
if (error.code === 2) {
ToastAndroid.show(
'定位失败,请查看手机是否开启GPS定位服务',
ToastAndroid.SHORT,
);
} else if (error.code === 3) {
ToastAndroid.show(
'定位超时,请尝试重新获取定位',
ToastAndroid.SHORT,
// abortController = null;
getPositions = () => {
//获取位置再得到城市先后顺序,通过Promise完成
return new Promise((resolve, reject) => {
// this.abortController.signal.addEventListener('abort', () => {
// const error = {code: 100, message: 'Locating request is aborted.'};
// return reject(error);
// });
Geolocation.getCurrentPosition(
location => {
const longitude = location.coords.longitude; //经度
const latitude = location.coords.latitude; //纬度
// console.log('转换前')
// console.log('longitude:', longitude)
// console.log('latitude:', latitude)
let arr = GPS.gcj_encrypt(latitude, longitude);
// console.log('转换后')
// console.log('longitude:', arr['lon'])
// console.log('latitude:', arr['lat'])
rangeID.setByLocation(arr['lon'], arr['lat']);
this.setState({
isStarted: false,
isLocated: true,
});
},
error => {
reject(error);
this.setState({isStarted: false});
if (error.code === 2) {
ToastAndroid.show(
'定位失败,请查看手机是否开启GPS定位服务',
ToastAndroid.SHORT,
);
} else if (error.code === 3) {
ToastAndroid.show(
'定位超时,请尝试重新获取定位',
ToastAndroid.SHORT,
);
} else {
ToastAndroid.show('定位失败:' + error.message, ToastAndroid.SHORT);
}
},
{
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 50,
},
);
} else {
ToastAndroid.show('定位失败:' + error.message, ToastAndroid.SHORT);
}
},
{
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 50,
},
);
});
};
geoLocate = async () => {
if (Platform.OS === 'ios') {
await this.getPositions().catch();
} else {
const permissions = [PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION];
const granted = await PermissionsAndroid.requestMultiple(permissions);
if (granted['android.permission.ACCESS_FINE_LOCATION'] === 'granted') {
await this.getPositions().catch();
} else {
ToastAndroid.show('定位权限被禁止', ToastAndroid.SHORT);
}
});
};
geoLocate = async () => {
if (Platform.OS === 'ios') {
await this.getPositions().catch();
} else {
const permissions = [PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION];
const granted = await PermissionsAndroid.requestMultiple(permissions);
if (granted['android.permission.ACCESS_FINE_LOCATION'] === 'granted') {
await this.getPositions().catch();
} else {
ToastAndroid.show('定位权限被禁止', ToastAndroid.SHORT);
}
}
};
startLocating = () => {
// // eslint-disable-next-line no-undef
// this.abortController = new AbortController();
this.setState({isStarted: true});
this.geoLocate().then();
};
// cancelLocating = () => {
// if (this.abortController) {
// this.abortController.abort();
// this.abortController = null;
// }
// this.setState({isStarted: false});
// };
startStudy = () => {
acID.setFromServer().then(() => {
acID.joinMatch().then(user => {
this.props.navigation.navigate('区域PK中', user);
});
});
};
render() {
const {isStarted, isLocated} = this.state;
return (
<View style={styles.container}>
<Image source={isStarted ? Locating : Located} style={styles.image}/>
<Text numberOfLines={1} style={styles.text}>
当前所在区域{parseRangeID()}
</Text>
{isStarted ? (
<MyButton
containerStyle={styles.myButton.container}
disabled={true}
title="定位中"
// onPress={this.cancelLocating}
/>
) : (
<MyButton
containerStyle={styles.myButton.container}
title={isLocated ? '重新定位' : '开始定位'}
onPress={this.startLocating}
/>
)}
<MyButton
disabled={!isLegalRangeID()}
containerStyle={styles.myButton.container}
title="开始自习"
onPress={this.startStudy}
/>
</View>
);
}
};
startLocating = () => {
// // eslint-disable-next-line no-undef
// this.abortController = new AbortController();
this.setState({isStarted: true});
this.geoLocate().then();
};
// cancelLocating = () => {
// if (this.abortController) {
// this.abortController.abort();
// this.abortController = null;
// }
// this.setState({isStarted: false});
// };
startStudy = () => {
acID.setFromServer().then(() => {
acID.joinMatch().then(user => {
this.props.navigation.navigate('区域PK中', user);
});
});
};
render() {
const {isStarted, isLocated} = this.state;
return (
<View style={styles.container}>
<Image source={isStarted ? Locating : Located} style={styles.image} />
<Text numberOfLines={1} style={styles.text}>
当前所在区域{parseRangeID()}
</Text>
{isStarted ? (
<MyButton
containerStyle={styles.myButton.container}
disabled={true}
title="定位中"
// onPress={this.cancelLocating}
/>
) : (
<MyButton
containerStyle={styles.myButton.container}
title={isLocated ? '重新定位' : '开始定位'}
onPress={this.startLocating}
/>
)}
<MyButton
disabled={!isLegalRangeID()}
containerStyle={styles.myButton.container}
title="开始自习"
onPress={this.startStudy}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#F2E2CE',
//opacity: 0.5,
flex: 1,
},
text: {
flex: 1,
color: '#592202',
fontWeight: '400',
fontSize: parseInt(height, 10) / 35,
textAlign: 'center',
},
image: {
width: null,
height: null,
flex: 9,
},
myButton: {
container: {
flex: 3,
backgroundColor: '#F2E2CE',
//opacity: 0.5,
flex: 1,
},
text: {
flex: 1,
color: '#592202',
fontWeight: '400',
fontSize: parseInt(height, 10) / 35,
textAlign: 'center',
},
image: {
width: null,
height: null,
flex: 9,
},
myButton: {
container: {
flex: 3,
},
},
},
});
export default RangePKHome;
......@@ -23,6 +23,8 @@ target 'FZUStudyRoom' do
pod 'react-native-safe-area-context', :path => '../node_modules/react-native-safe-area-context'
pod 'react-native-amap-geolocation', :path => '../node_modules/react-native-amap-geolocation'
target 'FZUStudyRoomTests' do
inherit! :complete
# Pods for testing
......
const GPS = {
PI : 3.14159265358979324,
x_pi : 3.14159265358979324 * 3000.0 / 180.0,
delta : function (lat, lon) {
// Krasovsky 1940
//
// a = 6378245.0, 1/f = 298.3
// b = a * (1 - f)
// ee = (a^2 - b^2) / a^2;
var a = 6378245.0; // a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
var ee = 0.00669342162296594323; // ee: 椭球的偏心率。
var dLat = this.transformLat(lon - 105.0, lat - 35.0);
var dLon = this.transformLon(lon - 105.0, lat - 35.0);
var radLat = lat / 180.0 * this.PI;
var magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
var sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * this.PI);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI);
return {'lat': dLat, 'lon': dLon};
},
//WGS-84 to GCJ-02
gcj_encrypt : function (wgsLat, wgsLon) {
if (this.outOfChina(wgsLat, wgsLon))
return {'lat': wgsLat, 'lon': wgsLon};
var d = this.delta(wgsLat, wgsLon);
return {'lat' : wgsLat + d.lat,'lon' : wgsLon + d.lon};
},
//GCJ-02 to WGS-84
gcj_decrypt : function (gcjLat, gcjLon) {
if (this.outOfChina(gcjLat, gcjLon))
return {'lat': gcjLat, 'lon': gcjLon};
var d = this.delta(gcjLat, gcjLon);
return {'lat': gcjLat - d.lat, 'lon': gcjLon - d.lon};
},
//GCJ-02 to WGS-84 exactly
gcj_decrypt_exact : function (gcjLat, gcjLon) {
var initDelta = 0.01;
var threshold = 0.000000001;
var dLat = initDelta, dLon = initDelta;
var mLat = gcjLat - dLat, mLon = gcjLon - dLon;
var pLat = gcjLat + dLat, pLon = gcjLon + dLon;
var wgsLat, wgsLon, i = 0;
while (1) {
wgsLat = (mLat + pLat) / 2;
wgsLon = (mLon + pLon) / 2;
var tmp = this.gcj_encrypt(wgsLat, wgsLon)
dLat = tmp.lat - gcjLat;
dLon = tmp.lon - gcjLon;
if ((Math.abs(dLat) < threshold) && (Math.abs(dLon) < threshold))
break;
if (dLat > 0) pLat = wgsLat; else mLat = wgsLat;
if (dLon > 0) pLon = wgsLon; else mLon = wgsLon;
if (++i > 10000) break;
}
//console.log(i);
return {'lat': wgsLat, 'lon': wgsLon};
},
//BD-09 to GCJ-02
bd_decrypt : function (bdLat, bdLon) {
var x = bdLon - 0.0065, y = bdLat - 0.006;
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.x_pi);
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.x_pi);
var gcjLon = z * Math.cos(theta);
var gcjLat = z * Math.sin(theta);
return {'lat' : gcjLat, 'lon' : gcjLon};
},
//WGS-84 to Web mercator
//mercatorLat -> y mercatorLon -> x
mercator_encrypt : function(wgsLat, wgsLon) {
var x = wgsLon * 20037508.34 / 180.;
var y = Math.log(Math.tan((90. + wgsLat) * this.PI / 360.)) / (this.PI / 180.);
y = y * 20037508.34 / 180.;
return {'lat' : y, 'lon' : x};
/*
if ((Math.abs(wgsLon) > 180 || Math.abs(wgsLat) > 90))
return null;
var x = 6378137.0 * wgsLon * 0.017453292519943295;
var a = wgsLat * 0.017453292519943295;
var y = 3189068.5 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
return {'lat' : y, 'lon' : x};
//*/
},
// Web mercator to WGS-84
// mercatorLat -> y mercatorLon -> x
mercator_decrypt : function(mercatorLat, mercatorLon) {
var x = mercatorLon / 20037508.34 * 180.;
var y = mercatorLat / 20037508.34 * 180.;
y = 180 / this.PI * (2 * Math.atan(Math.exp(y * this.PI / 180.)) - this.PI / 2);
return {'lat' : y, 'lon' : x};
/*
if (Math.abs(mercatorLon) < 180 && Math.abs(mercatorLat) < 90)
return null;
if ((Math.abs(mercatorLon) > 20037508.3427892) || (Math.abs(mercatorLat) > 20037508.3427892))
return null;
var a = mercatorLon / 6378137.0 * 57.295779513082323;
var x = a - (Math.floor(((a + 180.0) / 360.0)) * 360.0);
var y = (1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * mercatorLat) / 6378137.0)))) * 57.295779513082323;
return {'lat' : y, 'lon' : x};
//*/
},
// two point's distance
distance : function (latA, lonA, latB, lonB) {
var earthR = 6371000.;
var x = Math.cos(latA * this.PI / 180.) * Math.cos(latB * this.PI / 180.) * Math.cos((lonA - lonB) * this.PI / 180);
var y = Math.sin(latA * this.PI / 180.) * Math.sin(latB * this.PI / 180.);
var s = x + y;
if (s > 1) s = 1;
if (s < -1) s = -1;
var alpha = Math.acos(s);
var distance = alpha * earthR;
return distance;
},
outOfChina : function (lat, lon) {
if (lon < 72.004 || lon > 137.8347)
return true;
if (lat < 0.8293 || lat > 55.8271)
return true;
return false;
},
transformLat : function (x, y) {
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0;
return ret;
},
transformLon : function (x, y) {
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0;
return ret;
}
};
export { GPS };
......@@ -5914,6 +5914,11 @@ react-native-action-button@^2.8.5:
dependencies:
prop-types "^15.5.10"
react-native-amap-geolocation@^1.1.2:
version "1.1.2"
resolved "https://registry.npmmirror.com/react-native-amap-geolocation/-/react-native-amap-geolocation-1.1.2.tgz#4388731828bbe84493ac5894d0df27b4402ae3c5"
integrity sha512-M8uUqfnfrKwJka1byooL/NHD7EkTBEwOYswQiqu7bBkB24AkGeFZbd3h1XzaVLVyuBNfjHHm+W+fO8Apghxr5g==
react-native-amap3d@^3.0.7:
version "3.0.7"
resolved "https://registry.npmmirror.com/react-native-amap3d/-/react-native-amap3d-3.0.7.tgz#51c38ef14d15d55abf52ac0dd34d762a0b88eabd"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册