mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import TKUnit = require("Tests/TKUnit");
|
|
import locationModule = require("location/location");
|
|
|
|
var LocationManager = locationModule.LocationManager;
|
|
var Location = locationModule.Location;
|
|
|
|
export var testIsEnabled = function () {
|
|
TKUnit.assert(LocationManager.isEnabled());
|
|
};
|
|
|
|
export var testLocation = function () {
|
|
var locationReceived;
|
|
|
|
var locationManager = new LocationManager();
|
|
|
|
locationManager.startLocationMonitoring(function(location) {
|
|
locationReceived = true;
|
|
}, function(error) {
|
|
console.log('Location error received: ' + error);
|
|
locationReceived = error;
|
|
}
|
|
);
|
|
|
|
var isReady = function () {
|
|
return locationReceived;
|
|
}
|
|
|
|
TKUnit.waitUntilReady(isReady, 3);
|
|
locationManager.stopLocationMonitoring();
|
|
TKUnit.assert(true === locationReceived, locationReceived);
|
|
};
|
|
|
|
export var testDistance = function () {
|
|
var locSofia = new Location();
|
|
locSofia.longitude = 42.696552;
|
|
locSofia.latitude = 23.32601;
|
|
var locNewYork = new Location();
|
|
locNewYork.longitude = 40.71448;
|
|
locNewYork.latitude = -74.00598;
|
|
var distance = LocationManager.distance(locSofia, locNewYork);
|
|
TKUnit.assert((distance > 10780000) && (distance < 10860000), "invalid distance " + distance);
|
|
};
|
|
|
|
export var testLastKnownLocation = function () {
|
|
var locationManager = new LocationManager();
|
|
var lastKnownLocation = locationManager.lastKnownLocation;
|
|
TKUnit.assert((lastKnownLocation != null), "There is no last known location");
|
|
};
|
|
|