MVVMCross IMvxGeoLocationWatcher 成功操作永远不会在 Android 上触发 [英] MVVMCross IMvxGeoLocationWatcher Success Action never fires on 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() + "
");
}
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...
推荐答案
Per Odahan 此处:一个>
Per Odahan here:
嗯...我调查了更多:这个问题是已知的,可以在许多设备上看到.这不是 MvvmCross 问题.简短回答:设备需要重新启动,并且一切都像魅力一样工作......似乎谷歌发送了一些导致问题的更新.这是一个讨论这个问题的线程和一个关于 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/问题/详细信息?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屋!