mrkeck Sharing the Love


Ionic 2 Geolocation.watchPosition Parameter 2 is not a function

Was getting this error "'watchPosition' on 'Geolocation': The callback provided as parameter 2 is not a function."
Turns out is a bug in "/node_modules/ionic-native/dist/plugins/geolocation.js"
Should have 3 params, was missing the 2nd parameter in "var watchId = navigator.geolocation.watchPosition(cb, options);"
So I added a function called cbe and put it in the 2nd param. (see below)

Geolocation.watchPosition = function (options) {
        return new Observable_1.Observable(function (observer) {
            var cb = function (data) { return; };
            var cbe = function (data) { return "err"; };
            var watchId = navigator.geolocation.watchPosition(cb, cbe, options);
            return function () { return navigator.geolocation.clearWatch(watchId); };

Extra backstory, in case it helps.
This line below threw no errors = Geolocation.watchPosition().subscribe((position) => {...

But if you wanted to have options, like enableHighAccuracy: true, it would fail = Geolocation.watchPosition({enableHighAccuracy: true}).subscribe((position) => {

In "/node_modules/ionic-native/dist/plugins/geolocation.d.ts" it tells it to use the default options "GeolocationOptions" if none are provided. But if you provide them is when it was running into the bug

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.