FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
NativeScript/location/location-common.ts at patch-1 · rclai/NativeScript · GitHub
rclai
/
NativeScript
Public
forked from
NativeScript/NativeScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
NativeScript
/
location
/
location-common.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
91 lines (79 loc) · 3.22 KB
Breadcrumbs
NativeScript
/
location
/
location-common.ts
Copy path
File metadata and controls
91 lines (79 loc) · 3.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
timer
=
require
(
"timer"
)
;
//import locationManagerModule = require("location/location-manager");
import
defModule
=
require
(
"location"
)
;
var
defaultGetLocationTimeout
=
20000
;
export
class
Location
implements
defModule
.
Location
{
public
latitude
:
number
;
public
longitude
:
number
;
public
altitude
:
number
;
public
horizontalAccuracy
:
number
;
public
verticalAccuracy
:
number
;
public
speed
:
number
;
// in m/s ?
public
direction
:
number
;
// in degrees
public
timestamp
:
Date
;
public
android
:
any
;
// android Location
public
ios
:
any
;
// iOS native location
}
export
var
getLocation
=
function
(
options
?:
defModule
.
Options
)
:
Promise
<
defModule
.
Location
>
{
var
timerId
;
var
locationManager
=
new
defModule
.
LocationManager
(
)
;
if
(
options
&&
(
0
===
options
.
timeout
)
)
{
return
new
Promise
<
defModule
.
Location
>
(
(
resolve
,
reject
)
=>
{
var
location
=
locationManager
.
lastKnownLocation
;
if
(
location
)
{
if
(
options
&&
(
"number"
===
typeof
options
.
maximumAge
)
)
{
if
(
location
.
timestamp
.
valueOf
(
)
+
options
.
maximumAge
>
new
Date
(
)
.
valueOf
(
)
)
{
resolve
(
location
)
;
}
else
{
reject
(
new
Error
(
"timeout is 0 and last known location is older than maximumAge"
)
)
;
}
}
else
{
resolve
(
location
)
;
}
}
else
{
reject
(
new
Error
(
"timeout is 0 and no known location found"
)
)
;
}
}
)
;
}
return
new
Promise
<
defModule
.
Location
>
(
(
resolve
,
reject
)
=>
{
if
(
!
defModule
.
LocationManager
.
isEnabled
(
)
)
{
return
reject
(
new
Error
(
"Location service is disabled"
)
)
;
}
locationManager
.
startLocationMonitoring
(
function
(
location
:
defModule
.
Location
)
{
if
(
options
&&
(
"number"
===
typeof
options
.
maximumAge
)
)
{
if
(
location
.
timestamp
.
valueOf
(
)
+
options
.
maximumAge
>
new
Date
(
)
.
valueOf
(
)
)
{
locationManager
.
stopLocationMonitoring
(
)
;
if
(
"undefined"
!==
typeof
timerId
)
{
timer
.
clearTimeout
(
timerId
)
;
}
resolve
(
location
)
;
}
}
else
{
locationManager
.
stopLocationMonitoring
(
)
;
if
(
"undefined"
!==
typeof
timerId
)
{
timer
.
clearTimeout
(
timerId
)
;
}
resolve
(
location
)
;
}
}
,
function
(
error
:
Error
)
{
console
.
error
(
'Location error received: '
+
error
)
;
locationManager
.
stopLocationMonitoring
(
)
;
if
(
"undefined"
!==
typeof
timerId
)
{
timer
.
clearTimeout
(
timerId
)
;
}
reject
(
error
)
;
}
,
options
)
;
if
(
options
&&
(
"number"
===
typeof
options
.
timeout
)
)
{
timerId
=
timer
.
setTimeout
(
function
(
)
{
locationManager
.
stopLocationMonitoring
(
)
;
reject
(
new
Error
(
"timeout searching for location"
)
)
;
}
,
options
.
timeout
||
defaultGetLocationTimeout
)
;
}
}
)
;
}
Back
|
FazBrowse Home
|
New Git URL