我需要帮助,这是watchPosition()
的问题,还是我做错了什么?
这是代码:
import { Geolocation } from '@ionic-native/geolocation';
private lat: any;
private lng: any;
constructor( private geolocation: Geolocation ) {
let watch = this.geolocation.watchPosition();
watch.subscribe((data) => {
// data can be a set of coordinates, or an error (if an error occurred).
this.lat= data.coords.latitude;
this.lng= data.coords.longitude;
},(error)=>{console.log(error);});
}
答案 0 :(得分:0)
如果要获取当前的纬度和经度,请使用getCurrentPosition方法
this.geolocation.getCurrentPosition().then((position) => {
this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude;
});