Open torhovland opened 3 years ago
As always, one can access those getters via Reflect::get
, and stringify manually, if wasm-bindgen doesn't expose an API correctly, at least, until it does.
Interesting! I'll try that as a possible better workaround.
Also, with help from "Calculator" on Discord, I got this working:
#[wasm_bindgen]
extern "C" {
type GeolocationCoordinates;
#[wasm_bindgen(method, getter)]
fn latitude(this: &GeolocationCoordinates) -> f64;
#[wasm_bindgen(method, getter)]
fn longitude(this: &GeolocationCoordinates) -> f64;
type GeolocationPosition;
#[wasm_bindgen(method, getter)]
fn coords(this: &GeolocationPosition) -> GeolocationCoordinates;
}
fn geo_callback(position: JsValue) {
let pos = JsCast::unchecked_into::<GeolocationPosition>(position);
let coords = pos.coords();
info!(
"Latitude: {}. Longitude: {}.",
coords.latitude(),
coords.longitude()
);
}
@torhovland thanks to your blogpost on the OSM app and this issue report, I could get Geolocation to work myself.
@CrimsonCodes0 what I found out is, that the WebIDL checked into the repository does not seem to match the latest draft.
I found the following differences compared to the latest draft:
GeolocationPosition
is used instead of Position
(https://w3c.github.io/geolocation-api/#position_interface)GeolocationCoordinates
, which is used in GeolocationPosition
(https://w3c.github.io/geolocation-api/#coordinates_interface)GeolocationPositionError
is used instead of PositionError
(https://w3c.github.io/geolocation-api/#position_error_interface)timeout
in PositionOptions
is now 0xFFFFFFFF
(https://w3c.github.io/geolocation-api/#position_options_interface)Would making this up to date 'just' involve changing the IDL file? Or is there a specific reason to keep this at the currently checked in version?
@torhovland I updated the bindings on the following branch https://github.com/mkroehnert/wasm-bindgen/tree/update-web-sys-geolocation
Will need to do some more testing before opening a pullrequest.
Describe the Bug
Given the following code:
and the following callback function:
the result is simply:
In other words, the returned
GeolocationPosition
doesn't contain thecoords
andtimestamp
properties that it should have.Expected Behavior
The sample
geo_callback
function above should log coordinates and a timestamp.Actual Behavior
Additional Context
It looks like this is related to https://stackoverflow.com/questions/32882035/cordova-geolocation-plugin-returning-empty-position-object-on-android/34302473#34302473
That indicates that
GeolocationPosition
doesn't contain actual properties, but getters. How do we make that work throughwasm-bindgen
?As a workaround, I am able to execute the geolocation code in Javascript, extract the values I need from
GeolocationPosition
and pass them to Rust usingwasm-bindgen
.