FuseJS/GeoLocation Module (JS)
Provides geolocation services.
Using geolocation services requires device authorization. Including the Fuse.GeoLocation
package
in your project will trigger a prompt for this authorization when the app is launched.
Use startListening to get continual location updates. Use location or getLocation for one-time location requests.
You need to add a reference to "Fuse.GeoLocation"
in your project file to use this feature.
This module is an EventEmitter, so the methods from EventEmitter can be used to listen to events.
Example
The following example shows how the different modes of operation can be used:
<JavaScript>
var Observable = require("FuseJS/Observable");
var GeoLocation = require("FuseJS/GeoLocation");
// Immediate
var immediateLocation = JSON.stringify(GeoLocation.location);
// Timeout
var timeoutLocation = Observable("");
var timeoutMs = 5000;
GeoLocation.getLocation(timeoutMs).then(function(location) {
timeoutLocation.value = JSON.stringify(location);
}).catch(function(fail) {
console.log("getLocation fail " + fail);
});
// Continuous
var continuousLocation = GeoLocation.observe("changed").map(JSON.stringify);
GeoLocation.on("error", function(fail) {
console.log("GeoLocation error " + fail);
});
function startContinuousListener() {
var intervalMs = 1000;
var desiredAccuracyInMeters = 10;
GeoLocation.startListening(intervalMs, desiredAccuracyInMeters);
}
function stopContinuousListener() {
GeoLocation.stopListening();
}
module.exports = {
immediateLocation: immediateLocation,
timeoutLocation: timeoutLocation,
continuousLocation: continuousLocation,
startContinuousListener: startContinuousListener,
stopContinuousListener: stopContinuousListener
};
</JavaScript>
<StackPanel>
<Text>Immediate:</Text>
<Text Value="{immediateLocation}" />
<Text>Timeout:</Text>
<Text Value="{timeoutLocation}" />
<Text>Continuous:</Text>
<Text Value="{continuousLocation}" />
<Button Text="Start continuous listener" Clicked="{startContinuousListener}" />
<Button Text="Stop continuous listener" Clicked="{stopContinuousListener}" />
</StackPanel>
```xml
In the above example we're using the @EventEmitter `observe` method to create an @Observable from the
`"changed"` event. We can also listen to changes by using the `on` method, as follows:
GeoLocation.on("changed", function(location) { ... })
Locations returned by this module are JavaScript objects of the following form:
```json
{
latitude: a number measured in decimal degrees,
longitude: a number measured in decimal degrees,
accuracy: a number measured in meters
}
To handle errors from GeoLocation we can listen to the "error"
event, as follows:
GeoLocation.on("error", function(err) { ... })
Location
- Namespace
- Fuse.GeoLocation
- Package
- Fuse.GeoLocation 2.9.1
Interface of GeoLocation
GetAuthorizationStatus() js
Returns the authorization status of GeoLocation
location : Location js
getLocation(timeout) js
isLocationEnabled() js
Returns whether or not the device has Geolocation enabled.
changed(location) js
error(error) js
Raised when an error occurs.
authorizationRequest js
startListening(minimumReportInterval, desiredAccuracy) js
stopListening() js
Inherited from NativeEventEmitterModule
Emit(object[]) uno
EmitError(string) uno
Call emit("error", reason)
on the underlying JS EventEmitter.
EmitErrorObject(string) uno
Call emit("error", new Error(reason))
on the underlying JS EventEmitter.
EmitFactory(Func<Context, object[]> (Context)) uno
EmitFactory<T>(Func<Context, T, object[]> (Context, T), T) uno
On(object, Callback (Context, object[])) uno
Connect a Callback to an event.
On(object, NativeEvent) uno
Inherited from NativeModule
AddMember(NativeMember) uno
Reset : EventHandler (object, EventArgs) ux
Inherited from Module
Dispose uno
Evaluate(Context, ModuleResult) uno
Evaluate(Context, string) : ModuleResult uno
Evaluated : EventHandler (object, EventArgs) ux
EvaluateExports(Context, string) : object uno
GetFile : FileSource uno
Returns the file source that will be watched by the Context for changes in Fuse preview. Override in subclasses and return correct file source to support live updates in Fuse preview.