capacitor-plugins
capacitor-plugins copied to clipboard
geolocation: getCurrentPosition options requires JSON stringify on iOS but not on Android and web.
Bug Report
Plugin(s)
@capacitor/geolocation": "6.0.0"
Capacitor Version
@capacitor/core": "6.0.0"
Platform(s)
iOS
Current Behavior
Using GeoLocation.getCurrentPosition(this.options)
with this.options
as JS Object works fine on web and Android. On iOS it throws the error: DataCloneError: The object can not be cloned.
.
Using GeoLocation.getCurrentPosition(JSON.stringify(this.options))
solves the error on iOS.
Expected Behavior
It should work always with a JS Object (Web, Android and iOS).
Additional Context
Using Vue 3 with options
from Vue data.
...
data() {
return {
options: {
timeout: 1000,
maximumAge: 1000,
enableHighAccuracy: true,
}
}
}
Because of the reactivity API (Proxy) of Vue 3 for data, I need to get the raw value of the proxy:
- Vue 3 Reactivity utils
import { toRaw } from 'vue'
const rawOptions = toRaw(this.options)
- Using JSON stringify/parse
const rawOptions = JSON.parse(JSON.stringify(this.options))
- Destructuring
const rawOptions = { ...this.options }
- With Object.assign
const rawOptions = Object.assign({}, this.options)
Use one of the possible ways above to get the raw value and then:
GeoLocation.getCurrentPosition(rawOptions)