我试图获取地址。到目前为止,我只使用
获取坐标 CLLocation loc = new CLLocation(anno.Coordinate.Latitude, anno.Coordinate.Longitude);
然而,我尝试了反向地理编码和地标。它们都不起作用。 以下示例未完成,格式不正确。我只是从swift复制。
async void ReverseGeocodeToConsoleAsync(CLLocation location)
{
var geoCoder = new CLGeocoder();
var placemarks = await
geoCoder.ReverseGeocodeLocationAsync(location);
var placemark = placemarks[0] as CLPlacemark;
var addressString = "";
//String to hold address
var locatedAtcountry = placemark.country;
var locatedAtcity = placemark.locality;
var locatedAtisocountry = placemark.ISOcountryCode;
if (placemark.ISOcountryCode == "TW") /*Address Format in Chinese*/
{
if (placemark.country != null)
{
addressString = placemark.country!
}
}
答案 0 :(得分:1)
看起来你的代码接近成功。这是一个可以从该位置获取地址的示例。
public void GetAddress(CLLocation loc)
{
CLGeocoder ceo = new CLGeocoder();
ceo.ReverseGeocodeLocation(loc, (placemarks, error) =>
{
CLPlacemark placemark = placemarks[0];
if (placemark != null)
{
Console.WriteLine(placemark.IsoCountryCode);
Console.WriteLine(placemark.Country);
}
});
}