c# - 如何在 Windows 8.1 App 中使用地理编码?

标签 c# windows-store-apps

我需要从地址获取地理坐标。我试着走这条路: http://www.braincastexception.com/wp7-web-services-first-part-geocodeservice/但有一些错误。

1) 错误的论点:

GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

2) 事件不存在:

geocodeService.GeocodeCompleted += (sender, e) => geoCode_GeocodeCompleted(sender, e);

本文涉及 Windows Phone 7,但我使用的是 Windows 8.1 应用程序。也许 Windows 8.1 App 有另一种解决方案?我该怎么办?

最佳答案

要进行地理编码,请执行以下操作:

async void GetLocation(string address, Geopoint queryHintPoint)
{
    var result = await MapLocationFinder.FindLocationsAsync(address, queryHintPoint);

    // Get the coordinates
    if(result.Status == MapLocationFinderStatus.Success)
    {
        double lat = result.Locations[0].Point.Position.Latitude;
        double lon = result.Locations[0].Point.Position.Longitude;
    }
}

并反向地理编码:

async void GetLocationName(Geopoint yourLocation)
{
    var result = await MapLocationFinder.FindLocationsAtAsync(yourLocation);

    // Get the address
    if(result.Status == MapLocationFinderStatus.Success)
    {
        string address = result.Locations[0].Address.StreetNumber + result.Locations[0].Address.Street;
    }
}

查看这篇文章:http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631249.aspx

它解释了如何在 Windows Phone 8.1 map 中获取位置。

关于c# - 如何在 Windows 8.1 App 中使用地理编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22514002/

相关文章:

c# - 是否值得为单个类抽象出对象创建?

c# - 为什么这个派生类的行为不同于它的基类

css - 自定义复选框/ radio 设计怪异

windows-8 - 基本页与空白页

c# - HttpClient 在没有 Fiddler 的情况下不解密 HTTPS

c# - 使用内部节点解析 XML?

c# - XAML 窗口显示图像模糊

javascript - 按钮元素不显示文本值

c# - 如何使用 sqlite-net 在适用于所有数据库模型的父类中实现插入、更新和删除?

multithreading - WinRT API 中是否有与 Android 处理程序等效的东西?