MVVMCross IMvxGeoLocationWatcher成功操作永远不会在Android上触发 [英] MVVMCross IMvxGeoLocationWatcher Success Action never fires on Android

查看:78
本文介绍了MVVMCross IMvxGeoLocationWatcher成功操作永远不会在Android上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的测试应用,以尝试将当前经纬度的地理编码反向转换为地址.

I created a very simple test app to try and reverse geocode my current lat/long into an address.

这是我的ViewModel的代码:

Here is the code for my ViewModel:

namespace LoginProductsMVVM.Core.ViewModels
{
    public class ProductDetailViewModel
        : MvxViewModel
    {
        public void Init(Product product)
        {
            Product = product;
        }

        private Product _product;
        public Product Product
        {
            get { return _product; }
            set { _product = value;
                RaisePropertyChanged (() => Product); }
        }

        private string _latitude;
        public string Latitude{
            get { return _latitude; }
            set { _latitude = value; RaisePropertyChanged(() => Latitude); }
        }

        private string _longitude;
        public string Longitude{
            get { return _longitude; }
            set { _longitude = value; RaisePropertyChanged(() => Longitude); }
        }

        private string _address;
        public string Address{
            get { return _address; }
            set { _address = value; RaisePropertyChanged(() => Address); }
        }

        private IMvxGeoLocationWatcher _watcher;
        public IMvxGeoLocationWatcher Watcher
        {
            get 
            {
                _watcher = Mvx.Resolve<IMvxGeoLocationWatcher> ();
                return _watcher;
            }
        }

        public ProductDetailViewModel(IMvxGeoLocationWatcher watcher)
        {
            _watcher = watcher;
            _watcher.Start (new MvxGeoLocationOptions (), OnLocation, OnError);
        }

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

            // Android Location specific stuff
            var activity = Mvx.Resolve<IMvxAndroidCurrentTopActivity> ().Activity;
            Geocoder geocdr = new Geocoder (activity.BaseContext);

            IList<Address> addresses = geocdr.GetFromLocation (double.Parse(Latitude), double.Parse(Longitude), 1);

            addresses.ToList().ForEach ((addr) => Address += addr.ToString() + "\r\n\r\n");
        }

        void OnError (MvxLocationError error)
        {
            Mvx.Error ("Seen location error {0}", error);
        }
    }
}

我的OnLocation方法中有一个断点,但从未到达那里.我是否缺少使它在Android上正常运行的功能?对于iOS来说似乎工作正常……

I have a break point in my OnLocation method but it never gets in there. Am I missing something for this to work properly on Android? It appears to work just fine for iOS...

推荐答案

每个Odahan 此处:

好吧...我进行了更多调查:这个问题是已知的,在很多设备上都可以看到.这不是MvvmCross问题.简短的回答:该设备需要重新启动,并且所有设备都像魅惑一样运转...看来Google发送了一些导致此问题的更新. 这是一个讨论此问题的线程,另一个涉及GeoCode类的线程:

Well... I investigated a bit more : The problem is known and can be seen on many devices. This is not a MvvmCross problem. Short answer : the device needs to be rebooted and all is working like a charm... It seems Google sent some updates that are causing the problem. Here is a thread speaking about this problem and a similar one concerning the GeoCode class :

https://code.google.com/p/android/issues/detail?id = 38009

因此:可以关闭,MvvmCross可以,但是其他人可以面对此错误,因此我的解释和此处的链接.

So : can be closed, MvvmCross is ok but others can face this bug so my explanations and the link here.

这篇关于MVVMCross IMvxGeoLocationWatcher成功操作永远不会在Android上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆