Angularjs 当我为currentlocation调用geolocation时,我面临这样的错误

Angularjs 当我为currentlocation调用geolocation时,我面临这样的错误,angularjs,ionic3,Angularjs,Ionic3,当我为currentlocation调用geolocation时,我面临这样的错误 TypeError: Object(...) is not a function at Geolocation.getCurrentPosition import { Geolocation } from '@ionic-native/geolocation/ngx'; constructor(public geolocation:Geolocation ){} this.geoloca

当我为currentlocation调用geolocation时,我面临这样的错误

 TypeError: Object(...) is not a function
 at Geolocation.getCurrentPosition 

import { Geolocation } from '@ionic-native/geolocation/ngx';
     constructor(public geolocation:Geolocation ){}
    this.geolocation.getCurrentPosition().then((resp) => {
     // resp.coords.latitude
     // resp.coords.longitude
    }).catch((error) => {
      console.log('Error getting location', error);
    });

我试图整理代码,因为我认为代码中的问题

 constructor(public navCtrl: NavController,private geolocation: Geolocation) { 

  navigator.geolocation.getCurrentPosition(this.onSuccess, this.onError);
    }
      onError(error) {
    alert('code: '    + error.code    + '\n' +
      'message: ' + error.message + '\n');
     }
     onSuccess(position) {
     let element = document.getElementById('map');
     element.innerHTML = 'Latitude: '  + position.coords.latitude      + '<br />' +
                  'Longitude: ' + position.coords.longitude     + '<br />' +
                  '<hr />'      + element.innerHTML;
                  console.log(element)
     }
构造函数(公共navCtrl:NavController,私有地理位置:地理位置){
navigator.geolocation.getCurrentPosition(this.onSuccess,this.onError);
}
onError(错误){
警报('code:'+error.code+'\n'+
'消息:'+error.message+'\n');
}
成功(职位){
let element=document.getElementById('map');
element.innerHTML='Latitude:'+position.coords.Latitude+'
'+ '经度:'+position.coords.Longitude+'
'+ “
”+element.innerHTML; console.log(元素) }
如果这不起作用,你可以看到这一点

此外,您可以在这里看到教程

因为
getCurrentPosition
不是函数,您将其称为
getCurrentPosition()
,所以它是一个对象(根据您的错误)。尝试放置console.log并检查是否已将ionic cli升级到版本4或更高版本?我的ionic版本是3.9.2我也有同样的问题!!!!!您应该尝试使用ionic v3插件和诊断插件中的isLocationEnabled()函数,您可以强制用户启用GPS,然后您可以使用此插件。geolocation.getCurrentPosition()希望这会有所帮助。