ios - 如何获取标注 c# xamarin 的 MKPlacemark 地址

标签 ios dictionary xamarin mkannotationview renderer

我正在尝试获取地址。到目前为止我所掌握的只是使用

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

最佳答案

看来您的代码已接近成功。这是一个可以从位置获取地址的示例。

        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);
                }
            });
        }

关于ios - 如何获取标注 c# xamarin 的 MKPlacemark 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47061017/

相关文章:

swift - 如何将元素附加到嵌套字典中的数组

python - 按键合并字典,并将字典名称作为子键

iOS : How to do proper URL encoding?

python - 从任意节点开始计算树中的内部(非叶)节点

ios - 当 UISlider 一直拖到最后时会触发什么事件?

c# - 如何在 Prism 应用程序中手动解析类型时获得正确的 INavigationService 实例

ios - Xamarin 单元测试不会加载到模拟器或手机 : "Cannot register two managed types ... with the same native name (' AppDelegate').“

ios - SKSpriteNode 将图像带到底部 - IOS 游戏

ios - 在 ScrollView 中垂直滚动时 ImageView 移到一边

ios - locationManager didExitRegion 或 locationManager didEnterRegion 从未调用