【发布时间】:2018-02-04 06:57:55
【问题描述】:
我有两段代码,一段从位置获取地址,另一段从地址获取位置。
GetAddressesForPosition
var geoCoder = new Geocoder();
Task.Run(async () =>
{
var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position);
Device.BeginInvokeOnMainThread(() =>
{
var firstAdress = possibleAddresses.FirstOrDefault();
GeolocationAdressEntry.Text = firstAdress;
//GeolocationAdressEntry.Text = $@"{firstAdresse.} {firstAdresse.PostalCode} {firstAdresse.Locality}";
});
});
对于这段代码,我没有任何异常,并且代码永远不会跟随
var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position);
GetPositionsForAddress
var elem = (Entry)sender;
var geoCoder = new Geocoder();
IEnumerable<Xamarin.Forms.Maps.Position> loc;
try
{
loc = await geoCoder.GetPositionsForAddressAsync(elem.Text);
var firstLoc = loc.FirstOrDefault();
var adress = elem.Text;
CreateNewPin(firstLoc, adress);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
对于这个它抛出了一个错误:“grpc failed”。如果需要,我可以发布完整的错误。
这很无聊,因为它在 IOS 中完美运行。
我尝试了具有不同版本的模拟器(Genymotion 和 adb)以及真实设备。同样的问题。
【问题讨论】:
-
我只在模拟器上得到这个,这是 Android 模拟器的一个已知限制。至于设备,我的代码适用于我拥有的所有测试设备,从 Android 4.4 -> Android 7.1。您确定已为您的 Android 项目正确设置了 Google API 密钥吗?
-
嗨,我忘记上传这个帖子了。你是完全正确的,这是一个模拟器问题,设备中的代码工作完美(似乎 4.4 有时需要重新启动才能工作)
标签: google-maps xamarin xamarin.android xamarin.forms geocoding