-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdata.js
More file actions
148 lines (140 loc) · 2.91 KB
/
data.js
File metadata and controls
148 lines (140 loc) · 2.91 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
export const data = [
{
latitude: '40.684922',
longitude: '-73.922862',
},
{
latitude: '40.685215',
longitude: '-73.920502',
},
{
latitude: '40.685526',
longitude: '-73.917746',
},
{
latitude: '40.684792',
longitude: '-73.917594',
},
{
latitude: '40.684028',
longitude: '-73.917540',
},
{
latitude: '40.683315',
longitude: '-73.917374',
},
{
latitude: '40.682554',
longitude: '-73.917182',
},
{
latitude: '40.682278',
longitude: '-73.919888',
},
{
latitude: '40.681955',
longitude: '-73.922433',
},
{
latitude: '40.681505',
longitude: '-73.925757',
},
{
latitude: '40.681268',
longitude: '-73.928466',
},
{
latitude: '40.680911',
longitude: '-73.931644',
},
{
latitude: '40.680915',
longitude: '-73.931642',
},
{
latitude: '40.682397',
longitude: '-73.931950',
},
{
latitude: '40.682055',
longitude: '-73.934774',
},
{
latitude: '40.682862',
longitude: '-73.935045',
},
{
latitude: '40.685649',
longitude: '-73.935628',
},
{
latitude: '40.685381',
longitude: '-73.938514',
},
];
// loopThroughArray(data, function (arrayElement) {
// console.log(arrayElement);
// }, 3000);
export function loopThroughArray(array, callback, interval) {
var newLoopTimer = new LoopTimer(function (time) {
if (array.length) {
var element = array.shift();
return callback(element, time - start);
}
}, interval);
var start = newLoopTimer.start();
}
// Timer
export function LoopTimer(render, interval) {
var timeout;
var lastTime;
this.start = startLoop;
this.stop = stopLoop;
// Start Loop
function startLoop() {
(timeout = setTimeout(createLoop, 0)), (lastTime = Date.now());
return lastTime;
}
// Stop Loop
function stopLoop() {
clearTimeout(timeout);
return lastTime;
}
// The actual loop
function createLoop() {
var thisTime = Date.now();
var loopTime = thisTime - lastTime;
var delay = Math.max(interval - loopTime, 0);
timeout = setTimeout(createLoop, delay);
lastTime = thisTime + delay;
render(thisTime);
}
}
const Screen2 = (props) => {
const [display, setDisplay] = useState('');
return (
<SafeAreaView style={styles.container}>
<Button
onPress={() => {
//loop through data and make call to db with location, return stores
loopThroughArray(
data,
async function (arrayElement) {
try {
const response = await axios.get(
`http://192.168.86.32:8080/api/stores/${arrayElement.longitude}/${arrayElement.latitude}/`
);
} catch (error) {
console.log(error);
}
},
60000
);
}}
title="button"
>
hi
</Button>
</SafeAreaView>
);
};