Skip to content

Instantly share code, notes, and snippets.

@BoHellgren
Created January 17, 2021 13:43
Show Gist options
  • Save BoHellgren/349bb16d4546351c5e3ac1d7ee841a0d to your computer and use it in GitHub Desktop.
Save BoHellgren/349bb16d4546351c5e3ac1d7ee841a0d to your computer and use it in GitHub Desktop.
@JS('navigator.geolocation') // navigator.geolocation namespace
library jslocation; // library name can be whatever you want
import "package:js/js.dart";
// locjs.getCurrentPosition(allowInterop((pos) => success(pos))
@JS('getCurrentPosition') // Accessing method getCurrentPosition from Geolocation API
external void getCurrentPosition(Function success(GeolocationPosition pos), Function error(var err), options);
@JS('watchPosition') // Accessing method watchPosition from Geolocation API
external void watchPosition(Function success(GeolocationPosition pos), Function error(var err), options);
@JS()
@anonymous
class GeolocationCoordinates {
external double get latitude;
external double get longitude;
external double get altitude;
external double get accuracy;
external double get altitudeAccuracy;
external double get heading;
external double get speed;
external factory GeolocationCoordinates(
{double latitude,
double longitude,
double altitude,
double accuracy,
double altitudeAccuracy,
double heading,
double speed});
}
@JS()
@anonymous
class GeolocationPosition {
external GeolocationCoordinates get coords;
external factory GeolocationPosition({GeolocationCoordinates coords});
}
@JS()
@anonymous
class GeolocationPositionError {
external int get code;
external String get message;
external factory GeolocationPositionError({int code, String message});
}
@JS()
external mapOptions(Options options);
@JS()
@anonymous
class Options {
external bool get enableHighAccuracy;
external double get timeout;
external double get maximumage;
// Must have an unnamed factory constructor with named arguments.
external factory Options({bool enableHighAccuracy, double timeout, double maximumage});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment