首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我为currentlocation调用geolocation时,我会遇到这样的错误

当我为currentlocation调用geolocation时,我会遇到这样的错误
EN

Stack Overflow用户
提问于 2019-02-14 19:24:40
回答 1查看 181关注 0票数 2

当我为currentlocation调用geolocation时,我会遇到这样的错误

代码语言:javascript
复制
 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);
    });
EN

回答 1

Stack Overflow用户

发布于 2019-02-28 08:38:07

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

代码语言:javascript
复制
 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)
     }

如果不起作用,您可以看到这个https://forum.ionicframework.com/t/geolocation-issues/157072/7

此外,您还可以在此处查看教程https://github.com/apache/cordova-plugin-geolocation#coords

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54689293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档