React-360: Geolocation issue

Created on 25 Aug 2017  路  3Comments  路  Source: facebookarchive/react-360

Hi,
When I try to use the Geolocation API I get:

Cannot read property 'getCurrentPosition' of undefined
> batchedMountComponentIntoNode@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 18867:15
> ReactNativeReconcileTransaction.perform@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 11092:16
> ReactNativeReconcileTransaction.closeAll@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 11128:25
> ReactNativeReconcileTransaction.close@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 19928:26
> CallbackQueue.notifyAll@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 10694:24
> <unknown>@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 11821:11
> measureLifeCyclePerf@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 11700:12
> <unknown>@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 11822:25
> react_example_body.componentDidMount@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 1252:29
> Object.getCurrentPosition@http://localhost:8081/index.vr.bundle?platform=vr&dev=true 17968:24
Cannot read property 'getCurrentPosition' of undefined

I've simply add this code to the example project (created with react-vr init WelcomeToVR):

 componentDidMount() {
       navigator.geolocation.getCurrentPosition(
             (position) => {console.log(JSON.stringify(position));},
             (error) => alert(error.message),
             {enableHighAccuracy: false}
       );
}

Am I missing something?
Thanks!

Most helpful comment

@baloo887 they're not intentionally replaced. The difference is that your React VR code runs in a web worker (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), so that your VR experience will always run at the maximum frame rate.

React Native includes APIs for geolocation, and I will re-implement them for React VR later today.

All 3 comments

Ran into a similar problem accessing things related to browser inside the VR app. I think since it runs inside a react-native context, the full functionality of the window/ navigator related stuff is not available.
Try using NativeModules instead since those are running on the browser thread.

@amitrajput1992 thanks for the suggestion. I've solved writing a custom Module to access the full navigator variable, and used it to expose the getCurrentLocation function.

From my understanding, mine is kind a of workaround.

Are window/navigator variables replaced by react native's ones for a specific reason?

@baloo887 they're not intentionally replaced. The difference is that your React VR code runs in a web worker (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), so that your VR experience will always run at the maximum frame rate.

React Native includes APIs for geolocation, and I will re-implement them for React VR later today.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stu60610 picture stu60610  路  4Comments

wuno picture wuno  路  3Comments

encodi picture encodi  路  4Comments

moroneyk picture moroneyk  路  3Comments

devsatish picture devsatish  路  3Comments