mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
minor location fixes and updates
This commit is contained in:
@ -1,4 +1,13 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
The current way of doing things have a limitation. Due to cyclic dependency
|
||||||
|
|
||||||
|
var LocationManager = require("location/location").LocationManager;
|
||||||
|
|
||||||
|
does not work! We need to rework it using image-source and console method of having common code in one class + specific implementations
|
||||||
|
for different OSes
|
||||||
|
*/
|
||||||
|
|
||||||
import types = require("location/location-types");
|
import types = require("location/location-types");
|
||||||
import promises = require("promises/promises");
|
import promises = require("promises/promises");
|
||||||
import locationModule = require("location/location");
|
import locationModule = require("location/location");
|
||||||
|
@ -95,9 +95,17 @@ export class LocationManager {
|
|||||||
var criteria = new android.location.Criteria();
|
var criteria = new android.location.Criteria();
|
||||||
criteria.setAccuracy((this.desiredAccuracy === types.Accuracy.HIGH) ? 1 : 2);
|
criteria.setAccuracy((this.desiredAccuracy === types.Accuracy.HIGH) ? 1 : 2);
|
||||||
this.locationListener = <any>new android.location.LocationListener({
|
this.locationListener = <any>new android.location.LocationListener({
|
||||||
onLocationChanged: function (location: android.location.Location) {
|
onLocationChanged: function (location1: android.location.Location) {
|
||||||
if (this._onLocation) {
|
if (this._onLocation) {
|
||||||
this._onLocation(LocationManager.locationFromAndroidLocation(location));
|
var location = LocationManager.locationFromAndroidLocation(location1);
|
||||||
|
if (this.maximumAge) {
|
||||||
|
if (location.timestamp.valueOf() + this.maximumAge > new Date().valueOf()) {
|
||||||
|
this._onLocation(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this._onLocation(location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -122,6 +130,7 @@ export class LocationManager {
|
|||||||
|
|
||||||
this.locationListener._onLocation = onLocation;
|
this.locationListener._onLocation = onLocation;
|
||||||
this.locationListener._onError = onError;
|
this.locationListener._onError = onError;
|
||||||
|
this.locationListener.maximumAge = (options && ("number" === typeof options.maximumAge)) ? options.maximumAge : undefined;
|
||||||
try {
|
try {
|
||||||
this.androidLocationManager.requestLocationUpdates(long(this.minimumUpdateTime), float(this.updateDistance), criteria, this.locationListener, null);
|
this.androidLocationManager.requestLocationUpdates(long(this.minimumUpdateTime), float(this.updateDistance), criteria, this.locationListener, null);
|
||||||
this.isStarted = true;
|
this.isStarted = true;
|
||||||
|
5
location/location.d.ts
vendored
5
location/location.d.ts
vendored
@ -112,4 +112,9 @@ export declare class LocationManager {
|
|||||||
lastKnownLocation: Location;
|
lastKnownLocation: Location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fires a single shot location search. If you specify timeout in options, location search will fail on timeout.
|
||||||
|
* If you specify timeout = 0 it just requests the last known location. However if you specify maximumAge and the
|
||||||
|
* location received is older it won't be received
|
||||||
|
*/
|
||||||
export declare var getLocation: (options?: Options) => promises.Promise<Location>;
|
export declare var getLocation: (options?: Options) => promises.Promise<Location>;
|
||||||
|
@ -80,6 +80,8 @@ export class LocationManager {
|
|||||||
setupWithFunctions: function (onLocation, onError) {
|
setupWithFunctions: function (onLocation, onError) {
|
||||||
this.onLocation = onLocation;
|
this.onLocation = onLocation;
|
||||||
this.onError = onError;
|
this.onError = onError;
|
||||||
|
|
||||||
|
this.maximumAge = (options && ("number" === typeof options.maximumAge)) ? options.maximumAge : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
}, {}).implements({
|
}, {}).implements({
|
||||||
@ -90,7 +92,15 @@ export class LocationManager {
|
|||||||
locationManagerDidUpdateLocations: function (manager, locations) {
|
locationManagerDidUpdateLocations: function (manager, locations) {
|
||||||
//console.log('location received: ' + locations.count());
|
//console.log('location received: ' + locations.count());
|
||||||
for (var i = 0; i < locations.count(); i++) {
|
for (var i = 0; i < locations.count(); i++) {
|
||||||
this.onLocation(LocationManager.locationFromCLLocation(locations.objectAtIndex(i)));
|
var location = LocationManager.locationFromCLLocation(locations.objectAtIndex(i));
|
||||||
|
if (this.maximumAge) {
|
||||||
|
if (location.timestamp.valueOf() + this.maximumAge > new Date().valueOf()) {
|
||||||
|
this.onLocation(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.onLocation(location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user