【问题标题】:How to obtain a MKPlacemark Address for a callout c# xamarin如何获取标注 c# xamarin 的 MKPlacemark 地址
【发布时间】:2017-11-01 18:01:11
【问题描述】:

我正在尝试获取地址。到目前为止,我使用

获取坐标
 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!
                    }
                } 

【问题讨论】:

    标签: ios dictionary xamarin mkannotationview renderer


    【解决方案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);
                    }
                });
            }
    

    【讨论】:

    • 非常感谢!毕竟尝试使用地图类渲染器。我决定改用更好的页面渲染器。 UiSearchBar 不起作用,因为我不知道如何为其设置事件。理想情况下,我想做类似的事情。但是使用搜索栏。
    • async void Handle_SearchButtonPressed(object sender, System.EventArgs e) { if (!string.IsNullOrWhiteSpace(SearchBar.Text)) { var address = SearchBar.Text; varsimilarLocations = await Geocoder.GetPositionsForAddressAsync(address);//没有完成
    • 你可以触发它:searchbar.SearchButtonPressed += (sender, e) => { /*Work to be done at time of Search button click*/ };
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 2010-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 1970-01-01
    相关资源
    最近更新 更多