MvvmCross IMvxGeoLocationWatcher永远不会激活MvxGeoLocation成功

时间:2013-07-31 16:47:33

标签: android xamarin mvvmcross

我正在使用MvvmCross Location插件。在某些设备上,MvxGeoLocation成功触发,而其他设备则永远不会触发。我已经看到其他类似问题的答案(MVVMCross IMvxGeoLocationWatcher Success Action never fires on Android)。但是,这不适用于所有设备(重新启动),因此解决方案无效。我正在测试的设备是在Android V 4.0.3,HTC Vivid上。客户端在其设备上报告相同的问题。下面是我的LocationService代码,OnLocation方法永远不会在这些设备上触发。

public class LocationService : ILocationService
{
    private readonly IMvxGeoLocationWatcher _locationWatcher;
    private readonly IMvxMessenger _messenger;

    public double Latitude { get; set; }
    public double Longitude { get; set; }

    public bool HasLocation()
    {
        return (Latitude != 0.0 && Longitude != 0.0);
    }

    public LocationService(IMvxGeoLocationWatcher locationWatcher, IMvxMessenger messenger)
    {
        _locationWatcher = locationWatcher;
        _messenger = messenger;
        _locationWatcher.Start(new MvxGeoLocationOptions(){ EnableHighAccuracy = true}, OnLocation, OnError);
    }

    private void OnError(MvxLocationError error)
    {
        _messenger.Publish(new GpsUnavailableMessage(this));
    }

    private void OnLocation(MvxGeoLocation location)
    {
        Latitude = location.Coordinates.Latitude;
        Longitude = location.Coordinates.Longitude;

        var message = new LocationMessage(this, location.Coordinates.Latitude, location.Coordinates.Longitude);
        _messenger.Publish(message);
    }
}

以下是LogCat中显示的消息,这看起来像我正在获取GPS位置吗?

07-31 11:54:59.883: V/GpsLocationProvider(246): SV count: 9 ephemerisMask: 93d5 almanacMask: 93d5
07-31 11:54:59.883: V/GpsLocationProvider(246): sv: 1 snr: 0.0 elev: 7.0 azimuth: 146.0 E A
07-31 11:54:59.883: V/GpsLocationProvider(246): sv: 3 snr: 0.0 elev: 33.0 azimuth: 49.0 E A
07-31 11:54:59.883: V/GpsLocationProvider(246): sv: 5 snr: 0.0 elev: 0.0 azimuth: 0.0 E A
07-31 11:54:59.883: V/GpsLocationProvider(246): sv: 7 snr: 0.0 elev: 74.0 azimuth: 351.0 E A
07-31 11:54:59.883: V/GpsLocationProvider(246): sv: 8 snr: 0.0 elev: 43.0 azimuth: 314.0 E A
07-31 11:54:59.883: V/GpsLocationProvider(246): sv: 9 snr: 0.0 elev: 36.0 azimuth: 312.0 E A
07-31 11:54:59.883: V/GpsLocationProvider(246): sv: 10 snr: 0.0 elev: 0.0 azimuth: 0.0 E A
07-31 11:54:59.883: V/GpsLocationProvider(246): sv: 13 snr: 0.0 elev: 39.0 azimuth: 188.0 E A
07-31 11:54:59.883: V/GpsLocationProvider(246): sv: 16 snr: 0.0 elev: 1.0 azimuth: 66.0 E A

这是一个Android问题的Mono吗?以下代码永远不会触发ILocationListener:

    [Register("requestLocationUpdates", "(Ljava/lang/String;JFLandroid/location/LocationListener;)V", "GetRequestLocationUpdates_Ljava_lang_String_JFLandroid_location_LocationListener_Handler")]
    public virtual void RequestLocationUpdates(string provider, long minTime, float minDistance, ILocationListener listener);

1 个答案:

答案 0 :(得分:0)

升级时,这似乎是Xamarin.Android的问题。完全卸载Xamarin.Android然后重新安装v 4.8解决了这个问题。