如何获取标注 c# xamarin 的 MKPlacemark 地址
How to obtain a MKPlacemark Address for a callout c# xamarin
我正在尝试获取地址。到目前为止,我只使用
获取坐标
CLLocation loc = new CLLocation(anno.Coordinate.Latitude, anno.Coordinate.Longitude);
不过,我尝试了反向地理编码和地标。 None 其中有效。
以下示例未完成且格式不正确。我只是从 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!
}
}
看来您的代码已接近成功。这是一个可以从位置获取地址的示例。
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);
}
});
}
我正在尝试获取地址。到目前为止,我只使用
获取坐标 CLLocation loc = new CLLocation(anno.Coordinate.Latitude, anno.Coordinate.Longitude);
不过,我尝试了反向地理编码和地标。 None 其中有效。 以下示例未完成且格式不正确。我只是从 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!
}
}
看来您的代码已接近成功。这是一个可以从位置获取地址的示例。
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);
}
});
}