-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.js
76 lines (70 loc) · 2.35 KB
/
Utils.js
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
/**
* CANT USE beacuse can't get values from geolocation. asycn await not working.
* promise not working.
* https://stackoverflow.com/questions/6847697/how-to-return-value-from-an-asynchronous-callback-function
*/
import Geolocation from 'react-native-geolocation-service';
export default class Utils {
static instance = null;
static getInstance() {
if (this.instance === null) {
this.instance = new Utils();
}
return this.instance;
}
key = 'AIzaSyBIHuu2CVqTKLmahKCE4wmHL3dStmIuViY'
getLocation() {
let location = null;
const hasLocationPermission = true;
if (hasLocationPermission) {
Geolocation.getCurrentPosition(
(position) => {
console.log('position: ' + JSON.stringify(position));
console.log('c:' + JSON.stringify(position.coords));
location = position.coords;
/**
* hhshshhhashshshshs
*/
},
(error) => {
// See error code charts below.
console.log(error.code, error.message);
location = null;
},
// { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
);
} else {
console.log('did not have permission for geolocation request');
location = null;
}
console.log('start')
kokaSoppa().then((res) => { hshshs}).then()
console.log('stopp');
return location;
}
/*
Geolocation.getCurrentPosition(
position => convertCoords(position),
error => this.setState({
error: error.message
}), {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 1000
},
)
*/
getAddress(location) {
if (location) {
if (location.latitude && location.longitude) {
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?latlng=${location.latitude},${location.longitude}&key=${this.key}`);
}
console.log('Could not get address from undefined location');
}
return Promise.resolve(undefined);
}
}
/**
* Android set up
* https://github.com/Agontuk/react-native-geolocation-service
*/