mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
BCL: some location updates
This commit is contained in:
@@ -73,7 +73,7 @@ export class LocationManager {
|
|||||||
constructor() {
|
constructor() {
|
||||||
// put some defaults
|
// put some defaults
|
||||||
this.desiredAccuracy = types.DesiredAccuracy.HIGH;
|
this.desiredAccuracy = types.DesiredAccuracy.HIGH;
|
||||||
this.updateDistance = 10;
|
this.updateDistance = 0;
|
||||||
this.minimumUpdateTime = 200;
|
this.minimumUpdateTime = 200;
|
||||||
this.isStarted = false;
|
this.isStarted = false;
|
||||||
|
|
||||||
|
|||||||
47
Location/location.d.ts
vendored
47
Location/location.d.ts
vendored
@@ -15,19 +15,19 @@ export declare class Location {
|
|||||||
latitude: number;
|
latitude: number;
|
||||||
longitude: number;
|
longitude: number;
|
||||||
|
|
||||||
altitude: number;
|
altitude: number; // in meters
|
||||||
|
|
||||||
horizontalAccuracy: number;
|
horizontalAccuracy: number; // in meters
|
||||||
verticalAccuracy: number;
|
verticalAccuracy: number; // in meters
|
||||||
|
|
||||||
speed: number; // in m/s ?
|
speed: number; // in m/s
|
||||||
|
|
||||||
direction: number; // in degrees
|
direction: number; // in degrees
|
||||||
|
|
||||||
timestamp: Date;
|
timestamp: Date;
|
||||||
|
|
||||||
public androidNative: any; // android Location
|
public androidNative: any; // android Location
|
||||||
public iosNative: any; // iOS native location
|
public iosNative: any; // iOS CLLocation
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class RegionChangeListener {
|
export declare class RegionChangeListener {
|
||||||
@@ -36,19 +36,52 @@ export declare class RegionChangeListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export declare class LocationManager {
|
export declare class LocationManager {
|
||||||
|
/**
|
||||||
|
* Report are location services switched ON for this device (on Android) or application (iOS)
|
||||||
|
*/
|
||||||
static isLocationEnabled(): boolean;
|
static isLocationEnabled(): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Measure distance in meters between two locations
|
||||||
|
*/
|
||||||
static distanceInMeters(loc1: Location, loc2: Location): number;
|
static distanceInMeters(loc1: Location, loc2: Location): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies desired accuracy in meters. Defaults to DesiredAccuracy.HIGH
|
||||||
|
*/
|
||||||
desiredAccuracy: number;
|
desiredAccuracy: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update distance filter in meters. Specifies how often to update. Default on iOS is no filter, on Android it is 0 meters
|
||||||
|
*/
|
||||||
updateDistance: number;
|
updateDistance: number;
|
||||||
// minimum time interval between location updates, in milliseconds (android only)
|
|
||||||
|
/**
|
||||||
|
* Minimum time interval between location updates, in milliseconds (android only)
|
||||||
|
*/
|
||||||
minimumUpdateTime: number;
|
minimumUpdateTime: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if location listener is already started. In this case all other start requests will be ignored
|
||||||
|
*/
|
||||||
isStarted: boolean;
|
isStarted: boolean;
|
||||||
|
|
||||||
// monitoring
|
// monitoring
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts location monitoring.
|
||||||
|
*/
|
||||||
startLocationMonitoring(onLocation: (location: Location) => any, onError?: (error: Error) => any);
|
startLocationMonitoring(onLocation: (location: Location) => any, onError?: (error: Error) => any);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops location monitoring
|
||||||
|
*/
|
||||||
stopLocationMonitoring();
|
stopLocationMonitoring();
|
||||||
|
|
||||||
// other
|
// other
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last known location from device's location services or null of no known last location
|
||||||
|
*/
|
||||||
getLastKnownLocation(): Location;
|
getLastKnownLocation(): Location;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ export class LocationManager {
|
|||||||
public updateDistance: number;
|
public updateDistance: number;
|
||||||
|
|
||||||
public isStarted: boolean;
|
public isStarted: boolean;
|
||||||
|
|
||||||
private iosLocationManager: CoreLocation.CLLocationManager;
|
private iosLocationManager: CoreLocation.CLLocationManager;
|
||||||
|
private listener: any;
|
||||||
|
|
||||||
private static locationFromCLLocation(clLocation: CoreLocation.CLLocation): types.Location {
|
private static locationFromCLLocation(clLocation: CoreLocation.CLLocation): types.Location {
|
||||||
var location = new types.Location();
|
var location = new types.Location();
|
||||||
@@ -89,9 +91,9 @@ export class LocationManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var listener = new LocationListener();
|
this.listener = new LocationListener();
|
||||||
listener.setupWithFunctions(onLocation, onError);
|
this.listener.setupWithFunctions(onLocation, onError);
|
||||||
this.iosLocationManager.delegate = listener;
|
this.iosLocationManager.delegate = this.listener;
|
||||||
this.iosLocationManager.desiredAccuracy = this.desiredAccuracy;
|
this.iosLocationManager.desiredAccuracy = this.desiredAccuracy;
|
||||||
this.iosLocationManager.distanceFilter = this.updateDistance;
|
this.iosLocationManager.distanceFilter = this.updateDistance;
|
||||||
this.iosLocationManager.startUpdatingLocation();
|
this.iosLocationManager.startUpdatingLocation();
|
||||||
|
|||||||
@@ -30,12 +30,6 @@ export class LocationRegion {
|
|||||||
public raduis: number; // radius in meters
|
public raduis: number; // radius in meters
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This might be implemented with a callback, no need of special type.
|
|
||||||
export class LocationChangeListener {
|
|
||||||
//onLocationChange(location: Location) {
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This might be implemented with two callbacks, no need of special type.
|
// TODO: This might be implemented with two callbacks, no need of special type.
|
||||||
export class RegionChangeListener {
|
export class RegionChangeListener {
|
||||||
onRegionEnter(region: LocationRegion) {
|
onRegionEnter(region: LocationRegion) {
|
||||||
|
|||||||
Reference in New Issue
Block a user