nightr/client/Nightr/src/app/services/my-geo-location.service.ts

35 lines
842 B
TypeScript

import { Injectable } from '@angular/core';
import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation";
@Injectable({
providedIn: 'root'
})
export class MyGeoLocationService {
loc: Location;
constructor() {
}
getLocation(): Promise<Location> {
this.isLocationEnabled();
var result = getCurrentLocation({
desiredAccuracy: 3,
timeout: 5000
});
return result;
}
private isLocationEnabled() {
isEnabled().then(function (isEnabled) {
if (!isEnabled) {
enableLocationRequest().then(function () {
}, function (e) {
alert("Error: " + (e.message || e));
});
}
}, function (e) {
alert("Error: " + (e.message || e));
});
}
}