使用Xamarin解析位置字符串时是否有任何问题?
EG。我通过地址" Buffalo,NY 14267"进入MonoTouch.CoreLocation.CLGeocoder.GeocodeAddressAsync(),然后抛出一个无用的异常。
但是,如果我使用的地址类似于" Addison,TX 75001"那就没有错误。
代码很简单:
CLPlacemark[] placemarks = await _geoCoder.GeocodeAddressAsync(new CLLocation((double)location.Latitude, (double)location.Longitude));
编辑:我使用 GeocodeAddressAsync 而非 ReverseGeocodeLocationAsync
答案 0 :(得分:2)
如果您从NSErrorException
或 ReverseGeocodeLocationAsync
获得GeocodeAddressAsync
,那么我假设您提供的是经度不佳或/和纬度或地址错误并获取域= kCLErrorDomain
和code
= 8,因此Apple没有关于您的请求的数据。
CLError.h
开始,代码= 8是:kCLErrorGeocodeFoundNoResult, // A geocode request yielded no result
尝试/抓住NSErrorException
并确定错误的域/代码:
try
{
var _geoCoder = new CLGeocoder();
var placemarks = await _geoCoder.ReverseGeocodeLocationAsync(new CLLocation(42.885441, -78.878471));
foreach (var placemark in placemarks)
{
Console.WriteLine(placemark.ToString());
}
placemarks = await _geoCoder.ReverseGeocodeLocationAsync(new CLLocation(232.965158, -96.876839));
foreach (var placemark in placemarks)
{
Console.WriteLine(placemark.ToString());
}
}
catch (Exception ex) when (ex is Foundation.NSErrorException)
{
var nsErrorException = ex as Foundation.NSErrorException;
Console.WriteLine($"{nsErrorException.Domain}:{nsErrorException.Code}");
}
50 Delaware Ave, 50 Delaware Ave, Buffalo, NY 14202, United States @ <+42.88550930,-78.87880640> +/- 100.00m, region CLCircularRegion (identifier:'<+42.88550930,-78.87880640> radius 70.84', center:<+42.88550930,-78.87880640>, radius:70.84m)
kCLErrorDomain:8