Compilation failure with simple geolocation example

I am trying to test the geolocation feature of ionic, as described in the documentation here:

This is on

	Cordova CLI: 6.5.0 
	Ionic CLI Version: 2.2.1
	Ionic App Lib Version: 2.2.0
	ios-deploy version: Not installed
	ios-sim version: Not installed
	OS: Linux 4.4
	Node Version: v7.7.3
	Xcode version: Not installed

When trying the simplest example in this documentation,

      Geolocation.getCurrentPosition().then((resp) => {
        // resp.coords.latitude
        // resp.coords.longitude
      }).catch((error) => {
        console.log('Error getting location', error);

compilation within “ionic serve” fails with

[14:47:26]  typescript: src/app/app.component.ts, line: 23 
            Property 'getCurrentPosition' does not exist on type 'typeof Geolocation'. 

      L23:        Geolocation.getCurrentPosition().then((resp) => {
      L24:          // resp.coords.latitude

[14:47:26]  transpile failed 

I tried to narrow it down by creating a simple ionic application from scratch as test case, but this fails too.
Code is available at:

Am I doing something obviously wrong here?


I am getting that too.

Don’t go off the type Geolocation, inject an instance instead:

constructor(geoloc: Geolocation) {
  geoloc.getCurrentPosition().then(() => {

@jimmy_peckme @ajeans Could it be because you’re targeting an outdated version of Ionic Native? Here’s an example of using plugins with Ionic Native 3.x++

An example would be @ionic-native/geolocation

I have also same error my code is below

please help me…
Thank you

Thanks for the video.
My understanding after watching this (and reading the message from @rapropos) was that:

Anyway, I tried that on my test project and after a few tests, I now have it working in the browser !!
Thanks a lot everyone!!

If anyone still struggles to make this work, please look at and see if that works for you.

Would it make sense to update the Geolocation page in the official documentation?


Looks like it’s already been done.

Thanks, I have mine working now.