Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
hdastageeri
hft_awado_app
Commits
8503b54f
Commit
8503b54f
authored
Jan 11, 2020
by
Ratnadeep Rajendra Kharade
Browse files
Updated location serice code to read altitude along with lat and lng.
parent
3fa8dab5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/app/services/location.service.ts
View file @
8503b54f
...
...
@@ -5,24 +5,30 @@ import { Subject } from 'rxjs';
providedIn
:
'
root
'
})
export
class
LocationService
{
public
preiousUserPosition
=
{
lat
:
48.783480
,
lng
:
9.180319
};
public
currentUserPosition
=
{
lat
:
48.783480
,
lng
:
9.180319
};
public
preiousUserPosition
=
{
lat
:
48.783480
,
lng
:
9.180319
,
altitude
:
250
};
public
currentUserPosition
=
{
lat
:
48.783480
,
lng
:
9.180319
,
altitude
:
250
};
liveLocationSubject
=
new
Subject
<
any
>
();
//Decalring new RxJs Subject
constructor
(
private
geolocation
:
Geolocation
)
{
let
watch
=
this
.
geolocation
.
watchPosition
({
enableHighAccuracy
:
true
,
maximumAge
:
10000
});
watch
.
subscribe
((
position
)
=>
{
console
.
log
(
'
IN WATCHER
'
)
console
.
log
(
'
lat
'
+
position
.
coords
.
latitude
);
console
.
log
(
'
lng
'
+
position
.
coords
.
longitude
);
console
.
log
(
position
);
let
altitude
=
position
.
coords
.
altitude
;
if
(
!
altitude
)
{
altitude
=
250
;
}
this
.
currentUserPosition
.
lat
=
position
.
coords
.
latitude
;
this
.
currentUserPosition
.
lng
=
position
.
coords
.
longitude
;
this
.
currentUserPosition
.
altitude
=
altitude
;
this
.
preiousUserPosition
.
lat
=
position
.
coords
.
latitude
;
this
.
preiousUserPosition
.
lng
=
position
.
coords
.
longitude
;
this
.
preiousUserPosition
.
altitude
=
altitude
;
this
.
getUserLiveLocation
(
this
.
currentUserPosition
);
},
(
errorObj
)
=>
{
console
.
log
(
'
e
rror getting live location, setting to previous location
'
);
console
.
log
(
'
E
rror getting live location, setting to previous location
'
);
this
.
getUserLiveLocation
(
this
.
preiousUserPosition
);
});
}
...
...
@@ -31,12 +37,21 @@ export class LocationService {
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
geolocation
.
getCurrentPosition
().
then
((
resp
)
=>
{
console
.
log
(
resp
);
let
lat
=
resp
.
coords
.
latitude
;
let
lng
=
resp
.
coords
.
longitude
;
let
altitude
=
resp
.
coords
.
altitude
;
if
(
!
altitude
)
{
altitude
=
250
;
}
this
.
currentUserPosition
.
lat
=
resp
.
coords
.
latitude
;
this
.
currentUserPosition
.
lng
=
resp
.
coords
.
longitude
;
this
.
currentUserPosition
.
altitude
=
altitude
;
this
.
preiousUserPosition
.
lat
=
resp
.
coords
.
latitude
;
this
.
preiousUserPosition
.
lng
=
resp
.
coords
.
longitude
;
this
.
preiousUserPosition
.
altitude
=
altitude
;
resolve
(
this
.
currentUserPosition
);
},
er
=>
{
console
.
log
(
'
error getting location setting to previous location
'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment