-1

I am getting the Javascript error "Uncaught TypeError: Illegal invocation" when running the code

var nativeGeoloation = window.navigator.geolocation.getCurrentPosition;
nativeGeoloation(function (){ alert("ok")});

I have tried calling the code in the context of the window, but get the same error:

nativeGeoloation.call(window,function (){ alert("ok")})

The background of this question is that I am trying to access the native version of the geolocation function that has been overwritten by another javascript library (cordova)

Fiach Reid
  • 6,149
  • 2
  • 30
  • 34

1 Answers1

1

The error I'm getting in Firefox is:

TypeError: 'getCurrentPosition' called on an object that does not implement interface Geolocation.

Change your code to:

var nativeGeoloation = window.navigator.geolocation;
nativeGeoloation.getCurrentPosition(function (){ alert("ok")});

(Note, you've also spelled nativeGeoloation incorrectly which might cause you problems down the road if you start to spell it correctly).

DEMO

Andy
  • 61,948
  • 13
  • 68
  • 95