我創建了一個非常簡單的測試應用程序,用於將當前經緯度的地理編碼反轉爲地址。MVVMCross IMvxGeoLocationWatcher成功動作絕不會在Android上觸發
這裏是我的ViewModel代碼:我OnLocation方法
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);
}
}
}
我有一個破發點,但它從來沒有在那裏得到。我是否錯過了一些可以在Android上正常工作的東西?它似乎工作得很好,適用於iOS ...
+1自己調查和張貼答案。 – Jacco