Xamarin形式地理编码Android [英] Xamarin Forms Geocode Android
问题描述
我有两段代码,一段是从一个位置获得地址,一个从地址获得位置。
I Have two pieces of code, one to get adresses from a position & one to get position from adress.
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}";
});
});
对于这段代码,我没有任何异常,代码也没有执行过。
For this code, I not have any exception and the code never goes after
var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position);
GetPositionsForAddress
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。如果需要,我可以发布完整的错误。
For this one it thrown an error : "grpc failed". If needed I can post the complete error.
这很无聊,因为它在IOS中完美运行。
This is boring because it works perfectly in IOS.
I尝试使用不同版本的仿真器(Genymotion& adb),并且使用真实设备。同样的问题。
I tried on emulators ( Genymotion & adb ) with different versions and also in a true device. Same issue.
推荐答案
问题来自仿真器。代码在真正的设备中工作。
The issue comes from the emulator. Code work in a true device.
这篇关于Xamarin形式地理编码Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!