地理位置 Ionic 3 始终 return“{}”
Geolocation Ionic 3 always return "{}"
我被这个问题困住了。我无法使用 Ionic Geolocation 获取坐标。始终 return 是“{}”。任何人都可以帮助我吗?这是我的代码。
import { Geolocation, GeolocationOptions } from '@ionic-native/geolocation';
constructor(
private geolocation: Geolocation,
public platform: Platform,
) {}
this.platform.ready().then(()=>{
this.geolocation.getCurrentPosition(options)
.then((position) => {
console.log('Geolocation successful', JSON.stringify( position));
this.app.alertMsg( JSON.stringify( position) );
// let query = '?lat=' + position.coords.latitude + '&lng=' + position.coords.longitude;
}).catch((error) => {
console.log('Error getting location', JSON.stringify( error));
});
})
请看这个。
Cordova Geolocation plugin returning empty position object on Android 弗洛克道森
Apparently, the getCurrentPosition() function returns a 'special' object in Android, which evaluates to {} when using JSON.stringify(). If I outputted the raw return object to the console, it turned out it wasn't empty at all.
并根据https://ionicframework.com/docs/native/geolocation/
可以通过
获取经纬度等
this.app.alertMsg(position.coords.longitude + ' ' + position.coords.latitude);
我被这个问题困住了。我无法使用 Ionic Geolocation 获取坐标。始终 return 是“{}”。任何人都可以帮助我吗?这是我的代码。
import { Geolocation, GeolocationOptions } from '@ionic-native/geolocation';
constructor(
private geolocation: Geolocation,
public platform: Platform,
) {}
this.platform.ready().then(()=>{
this.geolocation.getCurrentPosition(options)
.then((position) => {
console.log('Geolocation successful', JSON.stringify( position));
this.app.alertMsg( JSON.stringify( position) );
// let query = '?lat=' + position.coords.latitude + '&lng=' + position.coords.longitude;
}).catch((error) => {
console.log('Error getting location', JSON.stringify( error));
});
})
请看这个。 Cordova Geolocation plugin returning empty position object on Android 弗洛克道森
Apparently, the getCurrentPosition() function returns a 'special' object in Android, which evaluates to {} when using JSON.stringify(). If I outputted the raw return object to the console, it turned out it wasn't empty at all.
并根据https://ionicframework.com/docs/native/geolocation/
可以通过
获取经纬度等 this.app.alertMsg(position.coords.longitude + ' ' + position.coords.latitude);