Ionic Android定位方位始终为空

时间:2018-08-27 19:11:48

标签: android ionic3 android-location ionic-native google-location-services

我正在尝试查找位置方位/方向。

enter image description here

我尝试使用GoogleMap.getMyLocation()返回bearing作为undefined

this.map.getMyLocation({
    enableHighAccuracy: true
}).then((loc:MyLocation)=>{
    console.log(loc.bearing) //always undefined
})

即使LocationService.getMyLocation()也会返回undefined

LocationService.getMyLocation(option).then((location: MyLocation) => {
    console.log('location.bearing,',location.bearing);//undefined
});

我也尝试使用geolocation,但是heading返回null

this.watchsubscription = this.geolocation.watchPosition(
    {
        maximumAge: 0,
        timeout: 1000,
        enableHighAccuracy: true
    }
).pipe(
    filter((p) => p.coords !== undefined)//Filter Out Errors
)
.subscribe(position => {
    console.log(position.coords.heading) // null
});

作为最后的选择,我尝试使用deviceOrientation,它返回magneticHeadingtrueHeading,但是magneticHeading始终等于trueHeading,它们是没有给出我在GoogleMap应用中看到的正确方位。

this.Orientationsubscription = this.deviceOrientation.watchHeading().subscribe(
    (data: DeviceOrientationCompassHeading) =>{ 
        console.log(data); //
    });

如何在Android Ionic上获得方位/方位?

0 个答案:

没有答案