angularjs - 当我为当前位置调用地理定位时。我面临这样的错误
问题描述
当我为当前位置调用地理定位时。我面临这样的错误
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)
}
如果这不起作用,你可以看到这个https://forum.ionicframework.com/t/geolocation-issues/157072/7
另外,您可以在此处查看教程 https://github.com/apache/cordova-plugin-geolocation#coords
推荐阅读
- java - 在对其键和值进行排序后,将 java 对象打印为 JSON 字符串
- python - 替换长文档中的一组单词
- python - 递归函数范围内的列表未更新
- python - 如何根据字符串模式条件删除/删除/过滤熊猫数据框中的行?
- python - 使用dict定义Snakemake一输入多输出
- reactjs - 从 Google Places getDetails 回调异步返回值
- android - 如何在关闭状态下更改开关的拇指颜色
- android - 如何仅在意图选择器中显示 PDF 文件
- json - 如何遍历 HttpClient 返回的 JSON
- laravel - 非静态方法 Spatie\Analytics\Analytics::fetchMostVisitedPages() 不应在 laravel 8 中静态调用